Specify project file with msbuild

I need a command line to create a specific solution project using msbuild, as we do with devenv.com. At devenv.com, we can specify a draft solution using the following command

devenv.com /Build Release|x86 test.sln /project "testproject" 

Using the command line above, I can build testproject in test.sln using devenv.com. What is the command line for msbuild for the same solution.

thank

+89
tfs build release msbuild devenv
Dec 17
source share
5 answers
 msbuild test.sln /t:project /p:Configuration="Release" /p:Platform="x86" /p:BuildProjectReferences=false 

Note that in /t project name is assigned in the solution, it may differ from the project file name.

In addition, as described in How to create specific goals in solutions using MSBuild.exe :

If the project name contains any of the characters % , $ , @ ; . , ( , ) or ' , replace them with _ in the specified target name.

You can also create several projects at the same time:

 msbuild test.sln /t:project;project2 /p:Configuration="Release" /p:Platform="x86" /p:BuildProjectReferences=false 

To restore or clean, change /t:project to /t:project:clean or /t:project:rebuild

+155
Oct. 23 '13 at 6:29
source share

MSBuild actually works using projects, not solutions. The solution is used only for its parsing in a temporary project file in MSBuild. You just need to create the project of interest directly through MSBuild by running the following command.

 "msbuild testproject /p:Configuration=Release /p:Platform=x86" 

There is one important problem that I know that you can use the project directly, and not the solution: if you use a solution to express dependencies between projects, instead of adding links to the project and making it possible to develop a dependency build system automatically.

If you are executing a build order using the sln file, I recommend using these dependencies directly in the proj files and removing them from sln. This will allow you to directly link to any proj file from MSBuild, and all projects will be created independently without any additional work. You really should treat the sln file as a group of projects in order to simplify your work in Visual Studio, and not as embedding.

+14
Dec 19 '12 at 15:22
source share

Publishing Information to Future Seekers

Add the following command to the script construct and run it once. This will create accurate targets and other information that msbuild will use.

Example: if you have one . in the project name or folders msbuild will expect _ instead . .

 set MSBuildEmitSolution=1 

After receiving the information, update the script assembly with the necessary information.

+6
Nov 02 '16 at 5:12
source share

Just to add additional information, executing msbuild in the project folder will create a project file by default, since it is the only one there.

 >msbuild 

There are many uses for msbuild in this way. You can specify the proj file directly.

 >msbuild helloworld.csproj -t:Build. 

Check out the msbuild documentation for use, proj file requirements, and the benefits of building a project instead of a solution.

MS MSBuild Documentation

There are advantages to constructing this path, as mentioned by Mark Smith above.

+1
Mar 19 '19 at 19:16
source share

To do this, you need to know what the project goal name is, not necessarily the project name.

One way to find out is to use MSBuild against your SLN with the intended parameters after setting the MSBuildEmitSolution special environment variable to 1 .

 set MSBuildEmitSolution=1 msbuild my_stuff.sln /t:rebuild /p:Configuration=Release /p:Platform=x64 

I recently had to do this due to a very specific name for the purpose in nested directories. So, from my generated my_stuff.sln.metaproj file my_stuff.sln.metaproj I found my_stuff.sln.metaproj line:

<Target Name="Utils\Firewall\FirewallUtils:Rebuild">

This means that the command line to use ultimately,

 msbuild my_stuff.sln /t:Utils\Firewall\FirewallUtils:Rebuild /p:Configuration=Release /p:Platform=x64 
0
Mar 26 '19 at 22:10
source share



All Articles