MSBuild OutDir per project in solution

We use a dedicated project file for building our solution/projects. The automated build sometimes complains about failing unit tests due to incompatible assembly versions. By building every project to their own OutDir we solved the issue.

MSBuild tasks

Install the MSBuild tasks with the package manager console and add the .build folder it creates to source control.

install-package MSBuildTasks

Undo any changes to the project and package.config. The .build folder is all you’ll need.

Build project

Change the build project to get the projects in the solution using the MSBuild tasks.

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

 <PropertyGroup>
  <!-- Needed to import the assembly from the right location -->
  <MSBuildCommunityTasksPath>$(MSBuildThisFileDirectory).build</MSBuildCommunityTasksPath>
  <BuildOutput>$(MSBuildThisFileDirectory)bin</BuildOutput>
  <Configuration>Release</Configuration>
 </PropertyGroup>

 <!-- Needs MSBuildCommunityTasksPath to be set -->
 <Import Project="$(MSBuildThisFileDirectory).build\MSBuild.Community.Tasks.Targets"/>

 <Target Name="Build" DependsOnTargets="GetProjectsFromSolution">
  <!-- Build every project in the solution -->
  <MSBuild Projects="%(ProjectFiles.Fullpath)"
           <!-- OutDir specifies the location the assemblies end up -->
           Properties="Configuration=$(Configuration);
                       OutDir=$(BuildOutput)\%(ProjectFiles.Filename)\"
           Targets="Build"/>
 </Target> 
</Project>

References

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Tooling and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s