8

We have a solution file that contains some solution folders: libraries, unit-tests, applications, etc.

With Visual Studio 2010 we can build only the projects of a given folder by right-clicking on it and using "build" or "rebuild".

This is perfect on the developers' workstations, and we'd like to do the same on the continuous-integration server which uses MSBuild.

So, can we build a solution folder with MSBuild?

Or will we have to create a dedicated solution for each folder?

The conclusion of the below responses is that there isn't any built-in way to do that, but some workarounds:

  • create a dedicated solution with only the selected projects,
  • use a dedicated csproj that will build the selected projects,
  • add a new project which will reference the selected projects in the existing solution file.

I've chosen to use a dedicated solution file as it is the less intrusive and tricky way, though not the more flexible (the dedicated .csproj solution should offer full control).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pragmateek
  • 13,174
  • 9
  • 74
  • 108
  • There are many ways you can get this kind of capability, but not with the solution folder fature of the solution. Realize that solution files are second-class citizens in MSBuild. If you are willing to do some alternate customizations outside the solution, there are ways to do what you want, is that an option? – Brian Kretzler Jun 07 '11 at 01:50
  • @Spider M9: thanks for taking the time to look at my issue. Any option is welcome, especially if simpler than the use of a dedicated solution file for each folder. – Pragmateek Jun 07 '11 at 09:02
  • @Serious Just to be sure: You want to build a single project out of a solution? – Filburt Jun 07 '11 at 09:16
  • @Filburt: I want to build a set of projects located in a solution folder, not just one. – Pragmateek Jun 07 '11 at 09:26
  • When you build the solution, it should build all of the projects (even the ones in solution folders) unless they're excluded from the current configuration. Similarly, you can build a solution (and all of its projects) from the command line by running msbuild on the .sln file. Could you give us a little more detail on what issue(s) you're facing? – Jim Lamb Jun 07 '11 at 10:15
  • @Jim: what I'm trying to achieve is not to build all the solution's projects, only a subset, those contained in a solution folder. – Pragmateek Jun 07 '11 at 13:43
  • See also http://stackoverflow.com/questions/6346556/how-do-i-target-a-specific-net-project-within-a-solution-using-msbuild-from-vs20 – Jeremy McGee Sep 12 '11 at 14:35

2 Answers2

6

Yes, you can build Solutions folders using MSBuild.

msbuild "framework.sln" /t:First\Project:Build

will build the project in the folder called First. However, disk folders and solutions folders must match (I tried it for my solution where they don’t first).

So all you'd have to do is choose a project that has all the other projects in that folder as dependencies.

Also see: MSBuild command-line reference

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
James Woolfenden
  • 6,498
  • 33
  • 53
  • thanks for the pointer. Indeed creating a project is yet another solution, but I'd prefer to avoid cluttering up the solution file with pure build content. So, again, the dedicated solution file seems the less intrusive solution. – Pragmateek Jun 07 '11 at 17:08
  • Not suggestting you do, id imagine that if your folder held related projects one might fulfil this role anyway eg a service project, but thanks for posing the question because i never knew that msbuild worked this way until i thought to look. One solution per built output is probably a better solution like you say though. – James Woolfenden Jun 08 '11 at 07:21
2

The short answer is:

Yes, if you want to build specific set of projects (grouped together in a VS solution) with plain MSBuild you will have to create a dedicated MSBuild .proj for each specific set of projects you want to build.

You will not have to create (and maintain) Visual Studio solutions to support your build, but in the end it's the same (an MSBuild .proj vs. a Visual Studio solution).

I have a similar scenario with a set of 60+ .NET projects (.btprpj BizTalk). For developing in Visual Studio, these projects are currently organized in 12 Visual Studio solutions.

For automated build and deploy I created a set of 50+ MSBuild .proj scripts to target every single component (or set of components) I need.

MSBuild offers a lot of possibilities for automating all the stuff around the actual build of the Visual Studio projects (export from version control systems, etc.).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Filburt
  • 17,626
  • 12
  • 64
  • 115
  • using a solution seems more usable because you can manipulate it easily with Visual, though there is less control. – Pragmateek Jun 07 '11 at 14:30
  • @Serious Actually I consider it a plus that MSBuild scripts are not like VS solutions ;-) – Filburt Jun 08 '11 at 12:18