How to exclude project from build in MSBUILD?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 07:23:09

问题


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.

ItemGroup section rise the following exception:

Invalid element . Unknown task or datatype.

PropertyGroup also rise 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>

So could anyone help me?


回答1:


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

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

msbuild /property:Configuration=Release MySolution.sln



回答2:


A solution suggested by Enrico is the most versatile solution that would work always. An alternative solution might be to use <MSBuild> task directly. This will work for you if you have all you project file under 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




回答3:


In your solution file (.sln), remove the Build.0 entries. For example:

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MyProject", "MyProject.vcxproj", "{2281D9E7-5261-433D-BB04-176A61500CA3}"
EndProject

GlobalSection(ProjectConfigurationPlatforms) = postSolution
    {2281D9E7-5261-433D-BB04-176A61500CA3}.Debug|x86.Build.0 = Debug|x64

If you delete this "Build.0" entry, it will load in the solution fine, but will not be built, either through the GUI or via external MSBuild.



来源:https://stackoverflow.com/questions/9778916/how-to-exclude-project-from-build-in-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!