Kylie
Kylie

Reputation: 141

How can i exclude projects from a solution build using msbuild?

I build my solution using MSBuild for vs2019

MSBuild.exe  "MyTestSolution.sln" /property:Configuration=Release /t:Rebuild 
/p:DefineConstants="testconstant" /p:OutputPath="C:\build"

But there are about 20 projects in the solution that get built. I want to exclude only 4 of them .

Is there a switch that i can us to exclude these projects ?

Upvotes: 0

Views: 2502

Answers (2)

Ross Youngblood
Ross Youngblood

Reputation: 536

I can recommend the book "Inside the Microsoft Build Engine" https://www.abebooks.com/9780735678163/Supplement-Microsoft-Build-Engine-Using-0735678162/plp

There is an ExcludeFrom Build property where you can add items, and perhaps create a configuration for your specific case. I've attached a screenshot from the book.

enter image description here

Upvotes: 2

Tianyu
Tianyu

Reputation: 1070

Checked the MSBuild CLI, and it seems no such Switch.

Listing the projects that you want to compile should be necessary. For example, using /target:MyProject1.csproj;MyProject2.csproj;MyProject4.proj. Of course, if there are some dependencies between your projects, you can use /target:MyProject1;MyProject2;MyProject4.

Example

Solution(folder) structure:

-MySolution
  -MyProject1
    -MyProject1.csproj
    -…
  -MyProject2
    - MyProject2.csproj
    -…
  -MyProject3
    - MyProject3.csproj
    -…
  -MyProject4
    - MyProject4.csproj
    -…

Command using:

  1. cd C:\MySolution.

  2. MSBuild.exe MySolution.sln /target:MyProject1;MyProject2;MyProject4

Upvotes: 2

Related Questions