无法使用cmd.exe在IIS托管的IIS中执行命令NG构建



我想使用C#代码执行NG构建来构建我的Angular项目。我在IIS上的C#应用程序托管。当我执行代码时,我会遇到错误:

ng'不被识别为内部或外部命令, r noperal程序或批处理文件。 r n

我创建了另一个我尚未在IIS上托管的应用程序,并且我正在使用Visual Studio在本地执行该应用程序。在同一代码中是工作属性。我无法弄清IIS的问题。我的代码如下。

private void buildAngular()
        {
            try
            {
                Process p = new Process();
                p.EnableRaisingEvents = true;
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.WorkingDirectory = @"D:AngularToBuildAngularProject";
                p.StartInfo.UseShellExecute = false;
                //p.StartInfo.Arguments = @"/c echo off > fff1.txt";
                p.StartInfo.Arguments = @"/c ng build";
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
                p.Exited += new EventHandler(myProcess_Exited);
                var err = p.StandardError.ReadToEnd();
                var msg = p.StandardOutput.ReadToEnd();
                Console.WriteLine("error", msg, err);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error");
            }
        }
        private void myProcess_Exited(object sender, System.EventArgs e)
        {
            Console.WriteLine("Exit time:    {0}rn" +
                "Exit code:    {1}rnElapsed time: {2}");
        }

ng.cmd位于 C:Users<user name>AppDataRoamingnpm中,但是默认应用程序池标识没有访问该文件夹的权限。

授予NTFS读取对应用程序池标识的权限,并确保文件夹包含在PATH环境系统变量中。

DefaultAppPool的默认应用程序池标识为IIS APPPOOLDefaultAppPool ..您需要将权限授予此帐户。

  1. 打开Windows Explorer
  2. 转到C:Users<user name>AppDataRoaming
  3. 右键单击npm
  4. 选择Properties
  5. 选择Security选项卡
  6. 单击edit按钮
  7. 单击add按钮
  8. 在文本框上输入IIS APPPOOLDefaultAppPool
  9. 单击Ok按钮
  10. 确保检查Read and ExecuteList Folder and ContentRead权限。
  11. 单击Ok
  12. 单击Ok

最新更新