我想使用c#代码执行ng build来构建我的角度项目。我在IIS上使用c#应用程序托管。当我执行代码时,我收到错误:
ng'无法识别为内部或外部命令,\ r \ noperable程序或批处理文件。\ 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:\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}");
}
答案 0 :(得分:1)
ng.cmd
位于C:\Users\<user name>\AppData\Roaming\npm
,但默认应用程序池标识无权访问该文件夹。
授予NTFS对应用程序池标识的读取权限,并确保该文件夹包含在PATH
环境系统变量中。
DefaultAppPool的默认应用程序池标识为IIS APPPOOL\DefaultAppPool
。您需要向此帐户授予权限。
C:\Users\<user name>\AppData\Roaming
npm
Properties
。Security
标签edit
按钮add
按钮IIS APPPOOL\DefaultAppPool
Ok
按钮Read and Execute
,List Folder and Content
和Read
权限已经过检查。Ok
Ok