我想使用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
..您需要将权限授予此帐户。
- 打开Windows Explorer
- 转到
C:Users<user name>AppDataRoaming
- 右键单击
npm
- 选择
Properties
。 - 选择
Security
选项卡 - 单击
edit
按钮 - 单击
add
按钮 - 在文本框上输入
IIS APPPOOLDefaultAppPool
- 单击
Ok
按钮 - 确保检查
Read and Execute
,List Folder and Content
和Read
权限。 - 单击
Ok
- 单击
Ok