Currently I am working on a C# WPF project which involves ShaderEffect
.
In the tutorials online regarding the use of this class, the HLSL shader code is either built manually using fxc.exe (i.e. importing the shader object directly into the project), or compiled at runtime using DirectX wrappers like SharpDX.
I want to compile the shader code at build time as one of the build tasks handled by MSBuild, so I can both (1) easily incorporate the shader code into version control and (2) prevent the project from bloating up.
Apparently there are two ways to achieve this, although both of them are incomplete.
- Packaging the shader code in a separate C++ project
The shader code could be included in a separate C++ project for which MSBuild supports HLSL compilation at build time. The sample project bundled with SharpDX is built this way.
However this sounds too roundabout to me. Why do I need a C++ project for a solution that contains absolutely zero lines of C++ code?
- Using
Microsoft.HLSL.CSharpVB
Microsoft.HLSL.CSharpVB
is a (seemingly abandoned) NuGet package from Microsoft that adds build actions for HLSL files.
I could confirm that the HLSL compiler is actually invoked when the build action is applied, but it does not work with WPF because WPF expects SM3.0 (or below?) and apparently I cannot change the target SM from the latest one (SM5.0 on my system) with this package.
It is barely believable that nobody else has encountered this problem before since ShaderEffect
has been around for a decade now.
Are there any clever ways to achieve what I want (HLSL compilation for WPF using MSBuild)?
Thank you in advance.