Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build project in 2017 Visual Studio from the command line?

In Visual Studio my project builds without any problem, but from command line I get the error "Hard error". Project .net (c#)

Command line:

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

 Process.Start(psinfo).WaitForExit();

I got error "Hard error" and Visual Studio crashed.

like image 334
NORM_4EL Avatar asked Dec 06 '16 10:12

NORM_4EL


1 Answers

You should use the MSBuild.exe or csc.exe instead of 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 requires more parameters ( and i think it requires to add some informations about projects ):

psinfo = new ProcessStartInfo(DEVENVPATH, @"""c:\Projects\[--pathtoproject--].sln"" /build RELEASE");
like image 130
Mateusz Avatar answered Nov 16 '22 01:11

Mateusz