7

I would like to compile a hlsl shader file in my C# project in Visual Studio 2015. With a C++ project I immediately get the correct properties if I add an hlsl file like the picture below:

HLSL build properties in C++

However when I want to do this in my C# project (with SharpDX) I do not get such options and thus can't compile to an CSO file for my project.

Does anyone know a solution for this?

leppie
  • 115,091
  • 17
  • 196
  • 297
N Jacobs
  • 341
  • 2
  • 16

2 Answers2

10

There's now a NuGet package, Microsoft.HLSL.CSharpVB, that adds support for HLSL shader properties to C# and VB projects:

This package installs MSBuild support for HLSL compilation in C# and VB projects.

Please reload your project or restart Visual Studio for the new shader Build Actions to appear in the properties window.

Tim Jones
  • 1,766
  • 12
  • 17
3

You can't do this directly in a C# project, as the Visual Studio HLSL compilation built-in integration is only working and accessible from a C++ project.

Though you could put an empty C++ project in the same solution, and then add and configure your HLSL files from there, and then reference generated cso files from your C# project as content (and add a project dependency from C# -> C++ project)... With some MSBuild trickery, you could also copy the generated content automatically into your C# project.

Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108
xoofx
  • 3,682
  • 1
  • 17
  • 32
  • 1
    This is indeed a nice workaround. Setting the output object file name of the HLSL files to $(SolutionDir)
    \%(Filename).cso. And then adding the cso file as a content file to the main project with the 'copy always' or 'copy if newer' did the trick.
    – N Jacobs May 20 '16 at 09:29