【问题标题】:Create Angular build(ng build) from C#从 C# 创建 Angular 构建(ng 构建)
【发布时间】:2018-09-07 22:57:09
【问题描述】:

所以我需要为一个 C# 项目(ashx 页面)创建一个 Angular 构建 (ng build --prod --aot-false),并将 Angular 文件夹作为项目的一部分。

我现在尝试的是在“src”文件夹外的 Angular 文件夹中创建一个 bat 文件,如下所示:

test.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# angular build


    【解决方案1】:

    这个帖子有点旧,但也许这对其他人有帮助。以下 sn-p 将从 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;
            }
    

    【讨论】:

      猜你喜欢
      • 2017-12-27
      • 2020-05-31
      • 1970-01-01
      • 2018-04-12
      • 2014-11-22
      • 2013-08-09
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多