Christian St.
Christian St.

Reputation: 1921

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

Upvotes: 4

Views: 4857

Answers (2)

Leo Liu
Leo Liu

Reputation: 76996

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.

Upvotes: 6

Emiel Koning
Emiel Koning

Reputation: 4225

If I use AfterTargets="Build" instead of AfterBuild, the message is written to the Output window every time I build the solution (.NET Core Console App with a .NET Standard Class Libary).

  <Target Name="MyAfterBuild" AfterTargets="Build">
    <Message Importance="High" Text="Hello World!" />
  </Target>

Upvotes: -1

Related Questions