无法使用cmd.exe在iis托管的asp.net Web应用程序中执行命令ng build [英] Unable to execute command ng build in iis hosted asp.net web app using cmd.exe
问题描述
我想使用C#代码执行ng build来构建我的有角项目.我已经在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 \不可操作的程序或批处理文件.\ 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
- 点击
确定
按钮 - 确保检查
Read and Execute
,List Folder and Content
和Read
权限. - 点击
确定
- 点击
确定
- 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!