After solving a problem, the best way to celebrate is to write a blog. Today, we solved a small problem and celebrated it.
What is this small problem?
A: In ASP. NET, how does one call MsBuild to compile a VS2010 solution?
What is the problem caused by this demand?
A: When a new version of a website is released, the browser triggers the Web server to retrieve the latest code from the Git version control server and then calls MsBuild for compilation...
How to solve this small problem:
A: In asp.net, run system.diagnostics.processto run msbuild.exe.
The Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" %>
<% @ Import Namespace = "System. Diagnostics" %>
<Script runat = "server">
Protected override void OnInit (EventArgs e)
{
String filePath = @ "C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ msbuild.exe ";
// Compile CNBlogsJob. sln in release Mode
ProcessStartInfo info = new ProcessStartInfo (filePath, @ "E: \ Dev \ CNBlogsJob. sln/p: Configuration = release ");
// Redirect console output to StandardOutput. If it is set to false, the console output result cannot be obtained.
Info. RedirectStandardOutput = true;
Info. UseShellExecute = false;
Process p = Process. Start (info );
// The following line of code is used to simulate the console display
Response. Write ("<body style = \" color: # DDD; background-color: #000; \ "> ");
// Console output result
Response. Write (p. StandardOutput. ReadToEnd (). Replace ("\ n", "<br/> "));
Response. Write ("</body> ");
P. WaitForExit ();
P. Close ();
}
</Script>
Result displayed in the browser: