微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 .Net 4 迁移到 5 会更改构建任务行为,并且不会将“中间输出”生成的资源包含到 dll 中

如何解决从 .Net 4 迁移到 5 会更改构建任务行为,并且不会将“中间输出”生成的资源包含到 dll 中

我正在将 WPF 应用从 .Net Framework 4 迁移到 .Net 5。 该应用程序依赖于一个(引用项目)库,该库允许一些自定义 hlsl 效果。 要将 hlsl 文件即时编译为 ps 文件并将它们包含在生成dll 文件中,我使用:this build task

使用 .Net Framework 4 使用该 csproj 文件效果库项目的)可以完美地工作:

<?xml version="1.0" encoding="utf-8"?>
<Project Toolsversion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="ShaderBuildTask.Pixelshadercompile" AssemblyName="ShaderBuildTask,Version=1.0.3072.18169,Culture=neutral,PublicKeyToken=44e467d1687af125" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">Anycpu</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{22A99010-4E29-47AA-994E-6CCE9C28D45F}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Comics.Effects</RootNamespace>
    <AssemblyName>Comics.Effects</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <OldToolsversion>3.5</OldToolsversion>
    <UpgradeBackupLocation />
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <Updaterequired>false</Updaterequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Anycpu' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
    <UseVSHostingProcess>false</UseVSHostingProcess>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Anycpu' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>bin\x64\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core">
    </Reference>
    <Reference Include="System.Xml.Linq">
    </Reference>
    <Reference Include="System.Data.DataSetExtensions">
    </Reference>
    <Reference Include="WindowsBase">
    </Reference>
    <Reference Include="PresentationCore">
    </Reference>
    <Reference Include="PresentationFramework">
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="DenoiseEffect.cs" />
    <Compile Include="BilateralEffect.cs" />
    <Compile Include="UnsharpEffect.cs" />
    <Compile Include="AdjustEffect.cs">
    </Compile>
    <Compile Include="EffectLibrary.cs">
    </Compile>
    <Compile Include="Properties\AssemblyInfo.cs" />
    <PixelShader Include="AdjustEffect.fx" />
    <PixelShader Include="BilateralEffect.fx">
      <ShaderModel>3_0</ShaderModel>
    </PixelShader>
    <Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
    <PixelShader Include="UnsharpEffect.fx">
      <ShaderModel>3_0</ShaderModel>
    </PixelShader>
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'">
    <AvailableItemName Include="VertexShader">
      <Visible>false</Visible>
    </AvailableItemName>
    <AvailableItemName Include="PixelShader">
      <Visible>false</Visible>
    </AvailableItemName>
  </ItemGroup>
  <ItemGroup>
    <PixelShader Include="DenoiseEffect.fx" />
  </ItemGroup>
  <UsingTask TaskName="ShaderBuildTask.shadercompile" AssemblyName="ShaderBuildTask,PublicKeyToken=44e467d1687af125" />
  <Target Name="Vertexshadercompile" Condition="'@(VertexShader)' != '' " BeforeTargets="Build">
    <shadercompile Sources="@(VertexShader)" ShaderProfile="vs_3_0" IntermediateOutputPath="$(IntermediateOutputPath)">
      <Output TaskParameter="Outputs" ItemName="Resource" />
    </shadercompile>
  </Target>
  <Target Name="Pixelshadercompile" Condition="'@(PixelShader)' != '' " BeforeTargets="Build">
    <shadercompile Sources="@(PixelShader)" ShaderProfile="ps_3_0" IntermediateOutputPath="$(IntermediateOutputPath)">
      <Output TaskParameter="Outputs" ItemName="Resource" />
    </shadercompile>
  </Target>
  <PropertyGroup>
    <PrepareResourcesDependsOn>Vertexshadercompile;Pixelshadercompile;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
  </PropertyGroup>
</Project>

但在迁移到 .Net 5 后,解决方案构建良好,ps 文件被编译到 obj 目录中,但 ps 文件未包含在 {{1 }},因此,使 dll 应用程序启动并立即崩溃(因为它需要 wpf 文件)。

这是新迁移的 ps 文件

csproj

唯一的区别是迁移到 .Net 5 和为简单起见删除<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <UsingTask TaskName="ShaderBuildTask.shadercompile" AssemblyName="ShaderBuildTask,PublicKeyToken=44e467d1687af125" /> <PropertyGroup> <TargetFramework>net5.0-windows</TargetFramework> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <UseWPF>true</UseWPF> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> <ItemGroup> <Compile Include="DenoiseEffect.cs" /> <Compile Include="BilateralEffect.cs" /> <Compile Include="UnsharpEffect.cs" /> <Compile Include="AdjustEffect.cs"> </Compile> <Compile Include="EffectLibrary.cs"> </Compile> <PixelShader Include="AdjustEffect.fx"> <ShaderModel>2_0</ShaderModel> </PixelShader> <PixelShader Include="BilateralEffect.fx"> <ShaderModel>3_0</ShaderModel> </PixelShader> <PixelShader Include="UnsharpEffect.fx"> <ShaderModel>3_0</ShaderModel> </PixelShader> <PixelShader Include="DenoiseEffect.fx" /> </ItemGroup> <UsingTask TaskName="ShaderBuildTask.shadercompile" AssemblyName="ShaderBuildTask,PublicKeyToken=44e467d1687af125" /> <Target Name="Vertexshadercompile" Condition="'@(VertexShader)' != '' " BeforeTargets="Build"> <shadercompile Sources="@(VertexShader)" ShaderProfile="vs_3_0" IntermediateOutputPath="$(IntermediateOutputPath)"> <Output TaskParameter="Outputs" ItemName="Resource" /> </shadercompile> </Target> <Target Name="Pixelshadercompile" Condition="'@(PixelShader)' != '' " BeforeTargets="Build"> <shadercompile Sources="@(PixelShader)" ShaderProfile="ps_3_0" IntermediateOutputPath="$(IntermediateOutputPath)"> <Output TaskParameter="Outputs" ItemName="Resource" /> </shadercompile> </Target> <PropertyGroup> <PrepareResourcesDependsOn>Vertexshadercompile;Pixelshadercompile;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn> </PropertyGroup> </Project> 。项目中没有其他任何内容修改

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。