Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to start Visual Studio 2008 Command Prompt and publish a web site (to a target path on my local drive). 

Bellow is the code I tried (which doesn't do anything):

I need to implement something like: 
msbuild /target:Build /p:BuildingProject=true;OutDir=C:\Temp\build\ ccosapp.sln

What I have tried:

ProcessStartInfo oInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat", @"msbuild C:\Users\Johan\Documents\Visual Studio 2008\Projects\PRJAPP\PRJAPP.sln");
oInfo.UseShellExecute = false;
oInfo.ErrorDialog = false;
oInfo.CreateNoWindow = true;
oInfo.RedirectStandardOutput = true;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(oInfo);
    System.IO.StreamReader oReader2 = p.StandardOutput;
    string sRes = oReader2.ReadToEnd();
catch (Exception ex)
Updated 17-Jun-16 1:52am

It makes no sense at all. Generally, CMD.exe is useless for programmatic use. This is nothing but yet another application, a command interpreter. Why "opening" it? You need applications or commands which you can start/run with CMD.exe, then run them, not CMD.exe.

You certainly need a way to build solutions. But you don't need to start Visual Studio for that. This is very important to build solutions and projects in one click, without Visual Studio. I explained how to do it in my recent answer: via MSBuild.EXE. For further detail, please see my recent answer: How I compile... using cmd?.

See also these answers:
How to automate the build process using MSBuild in C# .net,
Is there any event which can be fired during build process.

Share this answer
I See Sharp 16-Jun-16 3:02am    
I'm trying to publish a website, I need to define the target path for those files. But I don't know how to do this programmatically. Everything goes fine, except the publishing. Because the target is the only thing missing in my code bellow:

Type type = Type.GetTypeFromProgID("VisualStudio.DTE.9.0", true);
DTE dte = (DTE)System.Activator.CreateInstance(type, true);
dte.MainWindow.Visible = true;

VsWebSite.VSWebPackage webPkg = dte.GetObject("WebPackage") as VsWebSite.VSWebPackage;
webPkg.OpenWebSite(path, VsWebSite.OpenWebsiteOptions.OpenWebsiteOption_None, true);
SolutionBuild2 slnbld2 = (SolutionBuild2)webPkg.DTE.Solution.SolutionBuild;


And I have read that you can generate the files that are needed (to publish a web site) by running Visual Studio 2008 Command Prompt with the appropriate arguments. But even that doesn't go well.
Sergey Alexandrovich Kryukov 16-Jun-16 3:09am    
You original question was about build. Didn't I answer it. Publishing of a Web site could be as simple as FTP copy.
Sergey Alexandrovich Kryukov 16-Jun-16 9:23am    
Then start it. Command Prompt is an interactive application.
I don't know why though.
Don't you need a one-click batch to build and deploy at once? If so, do just that, without any "prompt".
Sergey Alexandrovich Kryukov 17-Jun-16 3:24am    
To do what? Interactive command-prompt session? Just start it? Use System.Diagnostics.Process.Start.
Anything else? Sorry, I am not sure you really understand what you need to achieve. If I'm missing something, please explain.
You cannot use two commands in the ProcessStartInfo constructor. You will need to build a script file that includes both commands and then start that script file with cmd.exe.
Share this answer
Richard MacCutchan 15-Jun-16 10:46am    
The command to start the script, i.e "cmd.exe" is the command, and the script name is the argument field. Mind you, it would be much quicker just to build in Visual Studio.
I came with this workaround:

1. I create a .bat file.
2. I write the commands in it.
3. Finally I start the .bat file as a Process.
StreamWriter w = new StreamWriter(@"C:\temp\publish.bat");
w.WriteLine(@"call ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat""");
w.WriteLine(@"call cd ""C:\Users\Johan\Documents\Visual Studio 2008\Projects\CCOSApp""");
w.WriteLine(@"call msbuild /target:Build /p:BuildingProject=true;OutDir=C:\Temp\build");
w.WriteLine("call ccosapp.sln");
System.Diagnostics.Process proc = new System.Diagnostics.Process();
ProcessStartInfo psi = new ProcessStartInfo(@"publish.bat");
psi.WorkingDirectory = @"C:\temp\";
proc.StartInfo = psi;
Share this answer
Richard MacCutchan 17-Jun-16 8:51am    
Which is what I told you yesterday.
I See Sharp 20-Jun-16 5:15am    
Yes, that's great.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900