Search code examples
visual-studiovisual-studio-2015msbuildmsbuild-task

Execute custom MSBuild task always after build process


I created a custom Task that executes after the build operation.

<Target Name="AfterBuild" />
<Target Name="MyTarget"
        AfterTargets="AfterBuild">
  <MyTask ... />
</Target>

QUESTION: Is it possible to execute the task, if the build operation was triggered, but did not perform, because there are no changes in the project / no need to build again?

In other words: I want to execute the task always at the end of the build process, even if the project was not built again.

UPDATE: Using AfterTargets="Build" or setting the property <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> does not help.

After triggering the Build process a second time, I only get the Output: Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped


Solution

  • Is it possible to execute the task, if the build operation was triggered, but did not perform, because there are no changes in the project / no need to build again?

    If I understand you correctly, you can define this property in your project file:

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

    Note: This method seems that Visual Studio is bypassing normal up-to-date checks of MSBuild and using some sort of custom check that is faster, but has a side effect of breaking customized build targets.

    Update: Not sure the reason why this method not work on your project, let me make the answer more detail:

    1. Define the property in your project file:
    2. Add the custom MSBuild task with some messages info.
    3. Build the project, check the output(log file verbosity is Normal).
    4. Build the project again, check the output again.