Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Build Files changes do not trigger project rebuild in VS 2017

In my C++ VS project I added a custom target to compile shader files and set it as a initial target. This is the project xml

<Project InitialTargets="CompileShaders" DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
 ..... Normal Default VS C++ content here ......

 <ItemGroup>
    <GLSLShader Include="SPIR-V\canvas2D.vert" />
    <GLSLShader Include="SPIR-V\canvas2D.frag" />
</ItemGroup>
 
  
  
  <Target Name="CompileShaders" Inputs="@(GLSLShader)" Outputs="SPIR-V\shaders_bytecode.h" >
    <PropertyGroup>
      <OriginalFileName>%(GLSLShader.Filename)%(GLSLShader.Extension)</OriginalFileName>
    </PropertyGroup>
    <Message Text="Start Compiling GSLANG @(GLSLShader) " />
    <Message Condition="'$(VULKAN_SDK)'==''" Text="Error, cant find environment variable VULKAN_SDK, Make sure that the  Lunar  Vulkan SDK is installed" />
    <Message Condition="'$(VULKAN_SDK)'!=''" Text="$(VULKAN_SDK)\Bin\glslangValidator.exe %(GLSLShader.Filename)%(GLSLShader.Extension) -V --vn $([System.String]::Copy('%(GLSLShader.Filename)%(GLSLShader.Extension)').Replace('.','_')) -o %(GLSLShader.Filename)%(GLSLShader.Extension).h" />
    <Exec Condition="'$(VULKAN_SDK)'!=''" Command="$(VULKAN_SDK)\Bin\glslangValidator.exe %(GLSLShader.Filename)%(GLSLShader.Extension) -V --vn $([System.String]::Copy('%(GLSLShader.Filename)%(GLSLShader.Extension)').Replace('.','_')) -o %(GLSLShader.Filename)%(GLSLShader.Extension).h" WorkingDirectory="$(ProjectDir)\SPIR-V" />
    <Exec Condition="'$(VULKAN_SDK)'!=''" Command="del shaders_bytecode.h" WorkingDirectory="$(ProjectDir)\SPIR-V" />
    <Exec Condition="'$(VULKAN_SDK)'!=''" Command="type %(GLSLShader.Filename)%(GLSLShader.Extension).h &gt;&gt; shaders_bytecode.h" WorkingDirectory="$(ProjectDir)\SPIR-V" />
    <Exec Condition="'$(VULKAN_SDK)'!=''" Command="del %(GLSLShader.Filename)%(GLSLShader.Extension).h" WorkingDirectory="$(ProjectDir)\SPIR-V" />
    
  </Target>
</Project>

if I change any .cpp .h file and build the solution, the shaders are compiled together with the rest of the project, but if I change only the shader files (i.e SPIR-V\canvas2D.vert) the project is not built. VS says that the project is up to date.

Now the strange thing, If I run the project using msbuild on the terminal ouside VS, the shader files changes are enough to trigger the rebuild. Go figure....!!!

It looks like something related to how VS build projects. It is outside the msbuild.

like image 792
alcoforado Avatar asked Sep 03 '25 03:09

alcoforado


1 Answers

Aha!! Found it in this article. It turns out visual studio bypass msbuild and uses some other criteria to verify if a project is up to date or not. If the criteria fails it then runs the msbuild on that project.

To override the visual studio behavior set the property DisableFastUpToDateCheck as true in the Globals property group of your project's xml:

<PropertyGroup Label="Globals">
    <!-- Other Global Property Settings -->
    <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

And it is done... I wonder if there is a away to tell Visual Studio FastUpToDateCheck Mechanism to also pay attention to the custom build files ????? The solution above will suffice for now.

like image 141
alcoforado Avatar answered Sep 04 '25 20:09

alcoforado