Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I target a specific .NET project within a Solution using MSBuild from VS2010?

I have an MSBuild command line that can build an entire solution. It looks something like this:

msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:Build

I know that for C++ Solutions, specific projects can be targeted using the following syntax:

msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:Folder\SomeCppProject;Build

I'm trying to achieve the same thing for .NET projects within a solution. This does NOT work:

msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:SomeDotNetProject;Build

Does anyone know how to target a specific project within a solution using MSBuild on the command line for .NET projects? I know I can create a custom MSBuild project to achieve what I'm after, but I need to share the solution and projects with Visual Studio.

Thanks!
-Sean

like image 382
Sean Aitken Avatar asked Jun 14 '11 16:06

Sean Aitken


People also ask

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 do you exclude a project from a 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 I use specific version of MSBuild?

Use 'where msbuild' to determine where it is loading msbuild from. Use the Visual Studio Command Prompt (2010) shortcut to initialize the path and other environment variables for VS 2010 and MSBuild 4.0. Don't forget, older MSBuild versions are also updated when newer .


1 Answers

You'll need to specify any solution folders in the Visual Studio solution file, and replace any "." in the project name with "_":

msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /t:Folder\Project_Name

For example, if you have a project in the solution folder "Deploy" named "MyApplication.Deployment.csproj", you'll need

msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /t:Deploy\MyApplication_Deployment

Incidentially this is a solution folder, as displayed in Visual Studio, not a file system folder: those are ignored.

like image 143
Jeremy McGee Avatar answered Sep 25 '22 21:09

Jeremy McGee