9

I have a solution which I have a number of unloaded projects. When I build the solution locally the unloaded projects are obviously not built. In Configuration Manager, I can't even select configuration, platform, build and deploy options for the unloaded projects.

Now I have created an Azure Pipeline which also builds the solution. But the unloaded projects are still being built.

How can I exclude building projects in my pipeline?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • In azure devops pipeline, we can't exclude projects to build. But we can specify projects to build in `arguments` input of build task. – LoLance Oct 01 '20 at 01:43

1 Answers1

23

Now I have created an Azure Pipeline which also builds the solution. But the unloaded projects are still being built.

Both Azure Devops Pipeline and VS IDE would call msbuild.exe to build. When building a solution using msbuild, it actually is running command msbuild xx.sln /t:build ....

Check the content of xx.sln file (solution file) we can find it defines definitions about the projects within the solution. That's why if you build the solution, all these projects will be built. This is expected behavior when building whole solution. Sample .sln file:

enter image description here

And it's VS IDE's magic to exclude unloaded projects when building whole solution. The IDE will check the unloaded projects and skip them when building whole solution, it has advantage that the unloading project behavior in IDE won't modify your solution file. (It's important for solution under Git version control).

To sum up: It's expected that building solution will build all projects. When we unload the projects in VS, this action won't affect our source solution file or project file. VS will automatically skip the unloaded projects, which is the unique feature of IDE. (Unload is a UI action in VS, it has no effect on .sln/.xxproj file)

To exclude projects to build in Azure Devops:

1.Specify projects to build when building whole solution. (It doesn't change any file, so that it won't affect Version control)

You can check this answer and corresponding document. My devops task setting (no need to specify Build target):

enter image description here

2.Exclude projects from solution configuration (Not recommended) or create a new configuration that excludes specific projects (Recommended). The solution configuration is defined in solution file (sln), so this way would makes effect on Source control.

Exclude projects from solution configuration(Not recommended):

enter image description here

Create a new configuration that excludes specific projects:

enter image description here

enter image description here

Related document here. I suggest you can do the changes via VS IDE, and then push the commits to remote repo. It's complex if you're not familiar with msbuild and sln file, so I doesn't suggest doing that yourself. Let IDE do the job for you.

Once the remote repo get the changes:

enter image description here

We can build the solution in devops with customrelease configuration which excludes ProjectA and ProjectB instead of release configuration which contains all projects.

enter image description here

All these workarounds had been tested on my side before posting them.

halfer
  • 19,824
  • 17
  • 99
  • 186
LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thanks for the detailed answer. I'd go with option 1 as it's more clear. – Ivan-Mark Debono Oct 01 '20 at 13:11
  • Glad to know it helps :) – LoLance Oct 02 '20 at 01:43
  • 1
    Hi Lance - a handful of writing tips, if I may, to save editors some work repairing these things over many of your answers: (1) where you add an explanatory parenthesis after something, a space goes before the opening bracket (like this), so that browsers know how to word-wrap appropriately; (2) the overuse of bold makes things harder to read and not easier; (3) code formatting is not a general highlighter, and is not necessary on proper nouns; (4) you do not need to invite readers to let you know if something does not work - they should know this already. – halfer Oct 12 '20 at 21:51
  • Option 1 was the solution for me as well, thanks! – tschan Jan 26 '21 at 19:40