1

So I'm developing a game engine framework for myself in C#/.NET and I have been trying to simplify building shader files (the rendering engine consumes SPIR-V files, which I want to generate from GLSL source). My current approach has been to use a custom .targets file which is imported into a CSPROJ, and that file defines a custom target like this:

<Target
    Name="Vert"
    AfterTargets="Build">
    <MakeDir Directories="$(OutputPath)%(VertShader.RelativeDir)"/>
    <Exec Command='"$(ENGINE_ROOT)\tools\glslang\windows-x64\glslangValidator.exe" -V %(VertShader.Identity) %(VertShader.OptLevel) -o $(OutputPath)%(VertShader.Identity).spv'></Exec>
</Target>

The general idea behind this is it takes VertShader items, runs the .vert file through glslang, and spits the output .vert.spv file into the build output directory. This works great, almost.

The problem is, if I have Project A that has a bunch of shaders, and then Project B which has a reference to Project A, I want to copy the .vert.spv shaders that Project A generates into the build output directory of Project B, but I haven't had much luck wrangling the target syntax to do what I want.

Is there any way I can get this working the way I'm describing?

2 Answers 2

0

I am not sure I understand your problem correctly, but if you want your .vert.spv copied to another folder use File.Copy()

1
  • The gist is I need Project A to contain some shader files, and what I want is for Project B to be able to reference Project A and have those shader files compiled and placed into its own output directory alongside the EXE when I build. Jan 14, 2022 at 3:37
0

Alright so I actually did manage to figure it out on my own I think, adding an answer in case it's helpful to anyone else. Adding this to my .targets file appears to allow them to be copied to any dependent project. I believe this is basically registering all of the files I'm creating with a list of files that MSBuild copies to whatever the current build output directory is (which causes them to get copied to any project that references this one)

<Target
    Name="IncludeVert"
    BeforeTargets="GetCopyToOutputDirectoryItems">
    <ItemGroup>
        <CompiledVerts Include="@(VertShader -> '$(OutputPath)%(RelativeDir)%(Filename).vert.spv' )">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <TargetPath>%(RelativeDir)%(Filename).vert.spv</TargetPath>
        </CompiledVerts>
        <AllItemsFullPathWithTargetPath Include="@(CompiledVerts->'%(FullPath)')"  />
    </ItemGroup>
</Target>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.