问题描述
我想使用 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.
- 打开 Windows 资源管理器
- 转到
C:\Users\\AppData\Roaming
- 右键单击
npm
- 选择
属性
. - 选择
安全
标签 - 点击
edit
按钮 - 点击
添加
按钮 - 在文本框中输入
IIS APPPOOL\DefaultAppPool
- 点击
确定
按钮 - 确保检查
读取和执行
、列出文件夹和内容
和读取
权限. - 点击
确定
- 点击
确定
- Open Windows Explorer
- Go to
C:\Users\<user name>\AppData\Roaming
- Right click on
npm
- Select
Properties
. - Select
Security
tab - Click on
edit
button - Click on
add
button - Enter
IIS APPPOOL\DefaultAppPool
on the text box - Click
Ok
button - Ensure
Read and Execute
,List Folder and Content
andRead
Permissions are checked. - Click
Ok
- Click
Ok
这篇关于无法使用 cmd.exe 在 iis 托管的 asp.net web 应用程序中执行命令 ng build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!