Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build only one project in a solution from command line

I have a solution with lots of solution folders with lots of c# projects inside them.

How do I build/rebuild only one of those projects from command line?

I guess there's some way to do it using msbuild but I don't know anything about msbuild.

Thanks!

like image 944
mmutilva Avatar asked Apr 05 '11 20:04

mmutilva


People also ask

How do you exclude a project from solution Build?

On the menu bar, choose Build > Configuration Manager. In the Project contexts table, locate the project you want to exclude from the build. In the Build column for the project, clear the check box. Choose the Close button, and then rebuild the solution.

How do you Build specific targets in solutions using MSBuild exe?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

How use MSBuild command line?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

What is the difference between MSBuild and Devenv?

The main advantage of MSBuild is that you don't need to have Visual Studio installed. One limitation of MSBuild is that it does not support building Visual Studio setup projects (. vdproj). (You can work around this by defining an exec task which calls devenv, but then you still need Visual Studio.)


2 Answers

Given a solution file with projects in it, and you want to build / rebuild one project.

This webpage on MSDN lists exactly what you have to do:

http://msdn.microsoft.com/en-us/library/ms171486.aspx

So given a solution file mysolution.sln with projects:

  • foo.vcxproj
  • bar.vcxproj
  • baz.vcxproj

where they all depend on each other in bottom to top order. So that baz is most independent, bar depends on baz and foo depends on bar.

If you want to build foo then you do:

MSBuild mysolution.sln /target:foo 

The other answers here didn't account about dependencies. Sure msbuild.exe will build a single project file (i.e. foo.vcxproj), but it would fail if bar and baz were not built yet. In order to build multiple projects and get the independent projects built first you have to pass in the solution file (After all the OP did mention this was part of a solution file). Then pass in the project name and a target delimited by a colon.

MSBuild mysolution.sln /target:foo:Rebuild 

Big assumption here. I'm assuming that the project name $(ProjectName) matches that of the file name.

Edit (from comment): If you happen to have dots (.) in the project name, you'll need to replace them with an underscore (_).

like image 148
C Johnson Avatar answered Sep 28 '22 11:09

C Johnson


You can simply call msbuild and pass it the .csproj/.vbproj project file that you want to build, and it will do only that one.

So something like:

cd \MySolution msbuild .\Project1\Project1.csproj 
like image 25
Joe Enos Avatar answered Sep 28 '22 09:09

Joe Enos