c# - 从 C# 创建 Angular build(ng build)

标签 c# angular build

所以我需要为 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/

相关文章:

c# - 寻找 PDF 文件解析器

c# - 身份证号码验证

javascript - 使用 Input 组件的 Angular 传递数据

angular - Angular 2 中的 ngSwitchCase 代替 ngSwitchWhen

c - getopt.h : Compiling Linux C-Code in Windows

c - VS2010 "Cannot open include file"错误

c# - Console.WriteLine 和通用列表

javascript - 第一个下拉列表选择不会过滤第二个下拉列表

git - netbeans cordova-构建我的项目时出错

c# - 仅使用一个(根)记录器时的 Log4net 重复条目