I'm migrating an WPF app from .Net Framework 4 to .Net 5.
That app rely on a (referenced project) library that allows some custom hlsl effects.
To compile hlsl files on the fly into ps files and include them in the generated dll file, i'm using: this build task.
This is working flawlessly using .Net Framework 4 using that csproj file (of the effect library project):
<?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, Version=1.0.3072.18169, Culture=neutral, 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>
But after migrating to .Net 5 the solution builds fine, the ps files are compiled into the obj directory, but the ps files aren't included into the dll, thus, making the wpf app launch and crash right after (as it needs the ps files).
Here is the new migrated csproj file:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<UsingTask TaskName="ShaderBuildTask.ShaderCompile" AssemblyName="ShaderBuildTask, Version=1.0.3072.18169, Culture=neutral, 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, Version=1.0.3072.18169, Culture=neutral, 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>
The only differences are the migration to .Net 5 and the removing of the run configurations for simplicity. Nothing else on the project has been modified.