Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2010: Need project to just act as trigger for MSBUILD script and to not compile to assembly

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?

like image 804
Laurence Avatar asked Dec 08 '11 13:12

Laurence


2 Answers

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:

  • before.SolutionName.sln.targets
  • after.SolutionName.sln.targets

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:

  • Extending the solution build
like image 101
Enrico Campidoglio Avatar answered Sep 20 '22 14:09

Enrico Campidoglio


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.

like image 39
ariscris Avatar answered Sep 21 '22 14:09

ariscris