无法使用 cmd.exe 在 iis 托管的 asp.net web 应用程序中执行命令 ng build [英] Unable to execute command ng build in iis hosted asp.net web app using cmd.exe

查看:37
本文介绍了无法使用 cmd.exe 在 iis 托管的 asp.net web 应用程序中执行命令 ng build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 c# 代码执行 ng build 来构建我的 angular 项目.我在 IIS 上由 c# 应用程序托管.当我执行代码时出现错误:

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' 不是内部或外部命令,也不是\r\n可运行的程序或批处理文件.\r\n

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

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

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}");
        }

推荐答案

ng.cmd 位于 C:\Users\\AppData\Roaming\npm 但默认应用程序池标识无权访问该文件夹.

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.

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

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

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

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

  1. 打开 Windows 资源管理器
  2. 转到C:\Users\<用户名>\AppData\Roaming
  3. 右键单击npm
  4. 选择属性.
  5. 选择安全标签
  6. 点击edit按钮
  7. 点击添加按钮
  8. 在文本框中输入IIS APPPOOL\DefaultAppPool
  9. 点击确定按钮
  10. 确保检查读取和执行列出文件夹和内容读取权限.
  11. 点击确定
  12. 点击确定
  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

这篇关于无法使用 cmd.exe 在 iis 托管的 asp.net web 应用程序中执行命令 ng build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆