asp.net中调用命令行

本文介绍了一种使用C#编写的Web应用程序自动编译指定解决方案的方法。通过调用MSBuild工具,以release配置模式编译位于特定路径下的解决方案文件,并将编译过程中的控制台输出实时展示在网页上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ 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";
string param = @" E:\Dev\CNBlogsJob.sln /p:Configuration=release";

filePath = "notepad.exe";
param = "";

//以release方式编译CNBlogsJob.sln
ProcessStartInfo info = new ProcessStartInfo(filePath, param);
//将控制台输出重定向至StandardOutput,如果为false,就无法得到控制台输出结果
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);
//下面一行代码是为了模拟控制台的显示效果
Response.Write("<body style=\"color:#DDD;background-color:#000;\">");
//控制台输出结果
Response.Write(p.StandardOutput.ReadToEnd().Replace("\n","<br/>"));
Response.Write("</body>");
p.WaitForExit();
p.Close();
}
</script>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值