Unable to execute command ng build in iis hosted asp.net web app using cmd.exe

痴心易碎 提交于 2021-01-28 11:46:48

问题


I want to execute ng build using c# code to build my angular project. I have hosted by c# application on IIS. When I am executing code I am getting error:

ng' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n

I have created another application that I have not hosted on IIS and I am executing that with locally using visual studio. In that same code is working property. I am unable to figure out issue with iis. My code is as below.

private void buildAngular()
        {
            try
            {

                Process p = new Process();
                p.EnableRaisingEvents = true;
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.WorkingDirectory = @"D:\AngularToBuild\AngularProject";
                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}\r\n" +
                "Exit code:    {1}\r\nElapsed time: {2}");
        }

回答1:


ng.cmd is located in C:\Users\<user name>\AppData\Roaming\npm but the default application pool identity has no permissions to access that folder.

Grant NTFS read permissions to application pool identity and make sure that folder is included in the PATH environment system variable.

The default app pool identity for DefaultAppPool is IIS APPPOOL\DefaultAppPool.. You need to grant permissions to this account.

  1. Open Windows Explorer
  2. Go to C:\Users\<user name>\AppData\Roaming
  3. Right click on npm
  4. Select Properties.
  5. Select Security tab
  6. Click on edit button
  7. Click on addbutton
  8. Enter IIS APPPOOL\DefaultAppPool on the text box
  9. Click Ok button
  10. Ensure Read and Execute, List Folder and Content and Read Permissions are checked.
  11. Click Ok
  12. Click Ok


来源:https://stackoverflow.com/questions/49549316/unable-to-execute-command-ng-build-in-iis-hosted-asp-net-web-app-using-cmd-exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!