Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does Visual Studio call target AfterBuild & BeforeBuild? And how is it handled when these targets are not defined?

Today I meet a similar problem and it reminds me about this thread. In Visual Studio, if we open the .csproj file, we see that they tell us to uncomment the two targets AfterBuild and BeforeBuild so as to execute them after and before the build of the current project accordingly.

My questions are: Where are these two targets called in Visual Studio? And how is it handled if the targets are not defined (be commented out) ?

like image 554
Nam G VU Avatar asked Jan 23 '23 07:01

Nam G VU


1 Answers

Those targets are contained in a file named Microsoft.Common.targets. This file is imported into your scripts via another import, Microsoft.CSharp.targets(or similar for other languages). So they are always defined when the build starts. In your project files you can override those targets by re-declaring them after the <Import statement for the file mentioned previously. If you declare them before the <Import then your targets will be ignored because the empty ones in Microsoft.Common.targets will be used.

For more info on extending the build process see my article Inside MSBuild or better yet my book Inside the Microsoft Build Engine!

In response to the previous commenter those targets are a part of the build process which builds your projects. They are captured in MSBuild files, and are neither a part of MSBuild nor Visual Studio.

like image 193
Sayed Ibrahim Hashimi Avatar answered Feb 02 '23 08:02

Sayed Ibrahim Hashimi