所以我需要为 C# 项目(ashx 页面)创建一个 Angular 构建(ng build --prod --aot-false
),并将 Angular 文件夹作为项目的一部分。
我现在尝试的是在“src”文件夹外的 Angular 文件夹内制作一个 bat 文件,如下所示:
测试.bat:
mkdir a
ng build --prod --aot=false
mkdir b
当我执行命令时,会立即创建目录“a”和“b”,但从未进行构建。
要执行我使用的流程:
文件处理程序.ashx:
System.Environment.CurrentDirectory =
context.Server.MapPath("~/ZipFiles/AngularProject_test/AngularProject/");
System.Diagnostics.Process.Start("test.bat");
最佳答案
这个线程有点旧,但也许这会对其他人有所帮助。以下代码段将从 C# 运行 ng build:
// this will be the path to your app
var workingDirectory = @"C:apps\angular-hello-world";
// location of ng command
var command = @"C:\Users\Owner\AppData\Roaming\npm\ng.cmd";
// any arguments you want to pass to ng
var arguments = "build --prod --base-href /helloworld/ --output-path=prod";
var process = new Process();
var currentDirectory = Environment.CurrentDirectory;
try
{
Environment.CurrentDirectory = workingDirectory;
process.StartInfo.FileName = command;
process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
// wait for the app to run and grab any output/errors generated
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
var errors = process.StandardError.ReadToEnd();
Console.WriteLine("Output: " + output);
Console.WriteLine("Errors: " + errors);
}
finally
{
Environment.CurrentDirectory = currentDirectory;
}
关于c# - 从 C# 创建 Angular build(ng build),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49548357/