Run console programs in ASP. NET

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.