visual studio – One .hlsl to many .cso


This is a visual studio problem not a MSBuild problem. So the solution is just to factor out the duplicate items into a separate MSBuild file

.vcxproj

<Import Project="MyShader.targets" />

MyShader.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <FxCompile Include="MyShader.hlsl">
      <PreprocessorDefinitions>USE_X=1</PreprocessorDefinitions>
      <ObjectFileOutput>MyShader_USEX.cso</ObjectFileOutput>
    </FxCompile>

    <FxCompile Include="MyShader.hlsl">
      <PreprocessorDefinitions>USE_Y=1</PreprocessorDefinitions>
      <ObjectFileOutput>MyShader_USEY.cso</ObjectFileOutput>
    </FxCompile>

    <FxCompile Include="MyShader.hlsl">
      <PreprocessorDefinitions>USE_X=1;USE_Y=1;USE_Z=1</PreprocessorDefinitions>
      <ObjectFileOutput>MyShader_XYZ.cso</ObjectFileOutput>
    </FxCompile>
  </ItemGroup>
</Project>

I have a python script to generate the .targets file


Edit:

My project didn’t load when I opened up visual studio this morning 🤦‍♂️. I’ve opened a ticket

https://developercommunity.visualstudio.com/t/Cannot-load-project-with-an-import-with/11045727

I’m just going to have my python script generate a file for each permutation.

Leave a Reply

Your email address will not be published. Required fields are marked *