Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild: How to ensure AfterBuild target always runs in a C++ project

I have added the following AfterBuild task to a .vcxproj file:

<Target Name="AfterBuild"> <Message Text="Hi" Importance="high" /> </Target>

It seems to run only if the the C++ code is built (or if I do a rebuild): 1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1> stdafx.cpp 1> SomeClass.cpp 1> ConsoleApplication1.vcxproj -> 1> Hi D:\Projects\CppTest\Debug\ConsoleApplication1.lib ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

It doesn't run when the the C++ code is up-to-date: ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

How can I make it always run? I'm using Visual Studio 2015.

like image 718
Frederick The Fool Avatar asked Jun 02 '26 13:06

Frederick The Fool


2 Answers

I got around this issue by adding the following lines to my .vcxproj file:

<PropertyGroup>
    <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

It seems to force the IDE to actually run MSBuild.

I tested it in Visual Studio 2015. Adding the same lines to an imported .targets file did not help.

like image 58
d11 Avatar answered Jun 04 '26 02:06

d11


The line

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

means that Visual Studio didn't run MSBuild at all.

For incremental builds VS uses File Tracker to intercept file operations being performed by compiler and linker. Results can be fould in ProjName.tlog folder. In subsequent builds VS checks dates of files listed in .read and .write files and decides whether to run MSBuild. This feature is described in Hashimi S., Bartholomew S. - Using MSBuild, 2nd Edition - 2013, "File Tracker" chapter.

Some of possible solutions:

  1. Use FileTracker API in your custom build tool.
  2. Manually write file name(s) produced by your tool in some .write file (this solution is simple but is not guaranteed to work in future VS versions).
  3. Build your solution by MSBuild instead VS.
  4. Build your solution from bat-file, which calls devenv first then your tool.
like image 37
Nikerboker Avatar answered Jun 04 '26 03:06

Nikerboker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!