Visual-studio – run MsBuild tasks (targets?) after the solution is built

msbuildvisual-studio

Since this question seems to have baffled / underwhelmed SO I will rephrase it with a partially formed idea of my own.

Could I somehow set up a batch file or something that runs after the whole solution is built, and this batch file would call msbuild to build specific targets inside a certain project? In order for it to work, I would have to somehow force msbuild build the target without regard to whether it thinks it's "up to date", because that is the core issue I'm butting up against.

Best Solution

Since you are dealing with building specifically you may want to replace your batch file with an MSBuild file. For example:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <SolutionsToBuild Include="MySolution.sln"/>

    <Projects Include="Proj1.csproj"/>
    <Projects Include="Proj2.csproj"/>
    <Projects Include="Proj3.csproj"/>
  </ItemGroup>

  <Target Name="BuildAll">

    <!-- Just executes the DefaultTargets (Build) -->
    <MSBuild Projects="@(SolutionsToBuild)"/>

    <!-- Call Rebuild if you think its not building correctly -->
    <MSBuild Projects="@(Projects)"
             Targets="Rebuild"/>

  </Target>
</Project>

Then you just invoke msbuild.exe on this file with:

msbuild.exe Build.proj /t:BuildAll

Since you said that you want to build specific projects after the solution is built just put those into the Projects ItemGroup as shown and use the MSBuild task to build them after the solution has been built. I've specified the Rebuild target to make sure you get a clean build.

Related Question