Reputation: 2779
I have the below code to build a project using MSBuild:
string process = sourcePath + @"\Application.sln /t:rebuild";
System.Diagnostics.Process csc = System.Diagnostics.Process.Start(@"C:\WINNT\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe",process);
This code worked before, I don't know why is not working any more.
If I do the same thing above by CMD it works fine, but not from VS.Net, the console window disappear fast so I can't see the error message.
If I debug the code I got this:
BasePriority = 'csc.BasePriority' threw an exception of type 'System.InvalidOperationException'
Is there any way to hold that screen so I can know what is happening here?
Upvotes: 0
Views: 2536
Reputation: 8850
Just start the cmd process with MSBuild.exe as an argument instead of directly starting the exe file.
string process = @"C:\WINNT\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe " + sourcePath + @" \Application.sln /t:rebuild";
System.Diagnostics.Process csc = System.Diagnostics.Process.Start(@"%windir%\system32\cmd.exe", process);
Upvotes: 3
Reputation: 4849
You can try to redirect the output of the msbuild you start using RedirectStandardOutput
Process compiler = new Process();
compiler.StartInfo.FileName = @"C:\WINNT\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe";
compiler.StartInfo.Arguments = sourcePath + @"\Application.sln /t:rebuild";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
Console.WriteLine(compiler.StandardOutput.ReadToEnd());
compiler.WaitForExit();
Upvotes: 2