Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude a project from a build in MSBuild?

I need to build a solution, but exclude one project. How should I do it?

I searched a lot about this issue, but nothing could help.

An ItemGroup section rises the following exception:

Invalid element . Unknown task or datatype.

PropertyGroup also rises the exception.

Below is my code sample:

<project name="TI 8.1.6 build script">   <ItemGroup>     <Solution Include="${ROOT}\Core\TI Core.sln" Exclude="${ROOT}\Utilities\DTS Indexing Service\Tdi.Origami.IndexUpdaterServiceSetup\Tdi.Origami.IndexUpdaterServiceSetup.wixproj"/>   </ItemGroup> ... </project> 

How can I do this?

like image 608
Andrew Lubochkn Avatar asked Mar 19 '12 22:03

Andrew Lubochkn


2 Answers

You can exclude projects at the solution level for a specific build configuration by using the Configuration Manager Dialog in Visual Studio:

Configuration Manager Dialog

Then you can simply invoke msbuild on the solution file specifying the build configuration to use:

msbuild /property:Configuration=Release MySolution.sln 
like image 79
Enrico Campidoglio Avatar answered Sep 19 '22 05:09

Enrico Campidoglio


The solution suggested by Enrico is the most versatile solution that would work always. An alternative solution might be to use a <MSBuild> task directly. This will work for you if you have all your project files under a particular directory, or be able to easily enumerate all projects you want to build (i.e. number of projects in your solution is not very big).

For example, this MSBuild file will build every project under your current directory except for a specific project:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">    <ItemGroup>     <MyProjectReferences Include="**\*.*proj" />     <MyProjectReferences Exclude="Utilities\DTS Indexing Service\Tdi.Origami.IndexUpdaterServiceSetup\Tdi.Origami.IndexUpdaterServiceSetup.wixproj" />   </ItemGroup>    <Target Name="BuildAllExceptWixProject">     <MSBuild Projects="@(MyProjectReferences)" Targets="Build" />   </Target>  </Project> 

Then you can build that using command line msbuild <myproject> /t:BuildAllExceptWixProject

like image 30
seva titov Avatar answered Sep 21 '22 05:09

seva titov