从命令行在2017 Visual Studio中构建项目?

NOR*_*4EL 8 c# visual-studio visual-studio-2017

在Visual Studio中,我的项目构建没有任何问题,但是从命令行我得到错误"硬错误".项目.net(c#)

命令行:

 psinfo = new ProcessStartInfo(DEVENVPATH, @"""c:\Projects\[--pathtoproject--].sln"" /build");
 psinfo.WindowStyle = ProcessWindowStyle.Hidden;
 psinfo.UseShellExecute = false;

 Process.Start(psinfo).WaitForExit();
Run Code Online (Sandbox Code Playgroud)

我收到错误"硬错误",Visual Studio崩溃了.

Mat*_*usz 6

您应该使用MSBuild.execsc.exe而不是devenv.exe.

const string COMPILER = "PATH/TO/DEV/TOOLS/msbuild.exe";
// later in code
psinfo = new ProcessStartInfo(COMPILER, "PATH\TO\PROJECT\PROJECT_NAME.sln /t:Rebuild /p:Configuration=Release");
Run Code Online (Sandbox Code Playgroud)

使用devenv进行编译需要更多参数(我认为它需要添加一些关于项目的信息):

psinfo = new ProcessStartInfo(DEVENVPATH, @"""c:\Projects\[--pathtoproject--].sln"" /build RELEASE");
Run Code Online (Sandbox Code Playgroud)