I have a solution with several web application projects in it. After all the projects have been built I need to run an MSBUILD script.
What I used to do was call the script from one of the existing projects (through <Target Name="AfterBuild">
in the .csproj file). However, I had to make sure I used the project that built last, and if the build order ever changed I would get unexpected results.
So, I decided to make an empty web application project, and set the project dependencies so that it always built last, then attach the MSBUILD script to this.
So now it always runs at the right time, but I get an extra (tiny) assembly as a result of the supposedly empty project being built. There are no code files in the project (except AssemblyInfo.cs), but an assembly is always produced.
So, is there either a way to stop the assembly being built, or maybe a way to attach the MSBUILD script to the solution as a whole and avoid this dummy project altogether?
In MSBuild 4.0 there are two new hooks that can be used to run scripts before and after a solution is built. When running MSBuild on a solution file, it will look for two target files in the solution directory:
If any of those files is found, it will automatically be executed at the proper stage.
In your case, in order to run a script after all the projects in the solution have been built, you could create an after.MySolution.sln.targets
file with a Target like:
<Target Name="RunPostBuildScripts" AfterTargets="Build">
<MSBuild Projects="PostBuild.targets" />
</Target>
See also:
I don't have enough reputation points to comment on the Enrico's accepted answer so I will just comment here that this doesn't work when you run the build in Visual Studio 2010 itself. It does work when MSBuild is run as a command-line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With