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

前端 未结 4 889
孤城傲影
孤城傲影 2020-11-28 09:34

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

相关标签:
4条回答
  • 2020-11-28 10:10

    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.

    0 讨论(0)
  • 2020-11-28 10:11

    create a master.proj file:

    in another ItemGroup add DefaultExclude properties for programs - put it in front of the solution -- BA was Canadian
    Configuration=Release Release drop the master.proj into the directory with the programs and msbuild the master.proj compiles everything except... that HelloWorld

    0 讨论(0)
  • 2020-11-28 10:15

    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

    0 讨论(0)
  • 2020-11-28 10:32

    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
    
    0 讨论(0)
提交回复
热议问题