build .net solution from batch file

2019-03-11 05:10发布

问题:

I have a solution file comprising of 15 projects using a few third party dll references. I want to be able to build the solution from a batch file. What is the best way to do this?

Thanks

回答1:

Run msbuild - for example:

msbuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU"


回答2:

One of the simplest ways is to execute msbuild with the solution file as input:

@echo off
call %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe path\to\solution.sln

If this is done in a Visual Studio command prompt you can skip the path to msbuild.exe.



回答3:

One way to get started is to open the project in Visual Studio and select Build | Rebuild Solution. Then go to View | Output. In the output window select "Build" in the Show Options From dropdown. This will display the commands that Visual Studio is using to build the project. You can paste those into a batch file, and read or modify them as desired.

If you want to maintain both Debug and Release versions of your application, then you will want to select the correct configuration and then follow the above steps for each version.