I would like to build a VS 2013 project from the command line.
After manually open the "Developer Command Prompt for VS2013", changing the directory to the project directory and inserting the following command
devenv myproject.csproj /build
the project is successfully built.
The problem is that I would like to do this from a C# function. I tried lot of things but none worked out.
When doing it manually I start the command prompt from a shortcut. The shortcut actually runs a .bat
file that sets up the environment so you can run commands like devenv
from the command prompt.
this is the code I am running
string runDevEnv = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>devenv.com ";
string projectPath = @"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\CodedUITestProject2\CodedUITestProject2\CodedUITestProject2.csproj" ;
string makeString = "\"";
string slashc = "/c ";
string makebuild = " /build";
string compileProject = slashc + runDevEnv + makeString + projectPath + makeString + makebuild;
System.Diagnostics.Process.Start("CMD.exe", compileProject);
It's probably easier to create a batch file to call devenv (if you really need to) but otherwise, I suspect it's just a matter of how you're quoting - and that you've got a >
in your path to devenv.exe
. Try:
string devEnv = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe";
string projectPath = @"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\CodedUITestProject2\CodedUITestProject2\CodedUITestProject2.csproj" ;
string compileProject = string.Format("/c \"{0}\" \"{1}\" /build",
devEnv, projectPath);
Process.Start("CMD.exe", compileProject);
(As noted in comments, you may well want to use devenv.com
instead of devenv.exe
, to prevent Visual Studio itself from starting up. If you can possibly use msbuild
instead, that would clearly be better - I know that isn't working for you immediately, but it would be worth investigating why instead of abandoning it.)
See more on this question at Stackoverflow