visual-studiomsbuildvisual-studio-2017projectvcxproj

How can I get VS to consider my project dirty when (only) an .exe Content item is dirty?


My C++ project includes a set of (non-code) files that need to be copied to the output directory verbatim. I added them to my .vcxproj as Content nodes with CopyToOutputDirectory set to PreserveNewest. For example:

<ItemGroup>
    <Content Include="util.exe">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="lib_util_needs.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <!-- etc. -->
</ItemGroup>

This almost works; when I build the project, each content file is correctly copied to the output directory if its timestamp is newer than whatever's already there. But... if I update one of these content files without modifying an actual compiled code file at the same time, Visual Studio 2017 concludes that the project is already up to date, does not build, and does not copy the newer version of the content file to the output directory. Is there anything I can do about this? Things that do not work:

Edit: After further investigation, it appears that the behavior depends on the content file's extension. For example, dlls behave the way I want (project marked as dirty and built if the timestamp is updated), but exes do not.


Solution

  • How can I get VS to consider my project dirty when (only) a Content item is dirty?

    You can set the property the UpToDateCheckInput to the item:

    <ItemGroup>
        <UpToDateCheckInput Include="util.exe">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </UpToDateCheckInput>
        <!-- etc. -->
    </ItemGroup>
    

    Or set the property DisableFastUpToDateCheck to true in the project file to disable FastUpToDateCheck for Visual Studio build manager:

    <PropertyGroup>
        <DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
    </PropertyGroup>
    

    Check MSDN about DisableFastUpToDateCheck:

    A boolean value that applies to Visual Studio only. The Visual Studio build manager uses a process called FastUpToDateCheck to determine whether a project must be rebuilt to be up to date. This process is faster than using MSBuild to determine this. Setting the DisableFastUpToDateCheck property to true lets you bypass the Visual Studio build manager and force it to use MSBuild to determine whether the project is up to date

    Hope this helps.