Build project in 2017 Visual Studio from the command line?
11,002
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");
Author by
NORM_4EL
Updated on June 05, 2022Comments
-
NORM_4EL almost 2 years
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.
-
NORM_4EL over 7 yearsThanks you!! Msbuild works. How to select project to build ?
-
mrogal.ski over 7 yearsto build only single project instead of
"PATH\TO\PROJECT\PROJECT_NAME.sln
you can do"PATH\TO\PROJECT\PROJECT_NAME.csproj
-
NORM_4EL over 7 years(if select csproj:) I got error "toolset", "build with 15.0, but need 12.0", how to select build toolset ? thanks
-
mrogal.ski over 7 yearstool set depends on the msbuild version you can check current version with developer console with
msbuild /ver
command. Basically the version is the version of VS. ( Microsoft Visual Studio 12.0 ) is Visual Studio 2013 -
NORM_4EL over 7 yearsI just use Process Hacker 2 and copy command line to build project with msbuild 2017: "project.csproj /nologo /clp:NoSummary /p:Configuration=""Release"" /p:Platform=""x86"" /v:m /t:Rebuild" and now works without error, thanks!
-
Michael Braude over 7 yearsJust call msbuild from a developer command prompt. msbuild will be on the path. msbuild will not be on the path for a regular command prompt.
-
mrogal.ski over 7 years@MichaelBraude msbuild ( as everything else ) is available from command line and developer console ( since it is just a file ). But Developer Command Prompt has simple shortcut ( variable ) to execute msbuild with a simple name command.
-
Michael Braude over 7 years@m.ragalski, what I mean is that it's not on the PATH any more. You need to specify the directly where it lives or modify your env variables manually.
-
yurislav almost 6 yearsfyi, path to mbsbuild.exe installed along VS2017 Communiity is `C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin`