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

时间:2016-12-06 10:22:58

标签: 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();

我收到错误“硬错误”并且Visual Studio崩溃了。

1 个答案:

答案 0 :(得分:6)

您应该使用 MSBuild.exe csc.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");

Compiling with devenv需要更多参数(我认为需要添加一些有关项目的信息):

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