问题
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' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n
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}");
}
回答1:
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.
Grant NTFS read permissions to application pool identity and make sure that folder is included in the PATH environment system variable.
The default app pool identity for DefaultAppPool is IIS APPPOOL\DefaultAppPool.. You need to grant permissions to this account.
- Open Windows Explorer
- Go to
C:\Users\<user name>\AppData\Roaming - Right click on
npm - Select
Properties. - Select
Securitytab - Click on
editbutton - Click on
addbutton - Enter
IIS APPPOOL\DefaultAppPoolon the text box - Click
Okbutton - Ensure
Read and Execute,List Folder and ContentandReadPermissions are checked. - Click
Ok - Click
Ok
来源:https://stackoverflow.com/questions/49549316/unable-to-execute-command-ng-build-in-iis-hosted-asp-net-web-app-using-cmd-exe