1

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}");
        }
5
  • which is the application pool identity? Commented Mar 29, 2018 at 6:41
  • application pool identity: DefaultAppPool Commented Mar 29, 2018 at 6:42
  • that is the application pool, not the application pool identity. The application pool identity is the account it runs under. Commented Mar 29, 2018 at 6:46
  • oh sorry. In ApplicationPoolIdentity "ApplicationPoolIdentity" is selected under DefaultAppPool . Commented Mar 29, 2018 at 7:04
  • Changing DefaultAppPool to LocalSystem worked. Now it is working. Commented Mar 29, 2018 at 7:15

1 Answer 1

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.

  1. Open Windows Explorer
  2. Go to C:\Users\<user name>\AppData\Roaming
  3. Right click on npm
  4. Select Properties.
  5. Select Security tab
  6. Click on edit button
  7. Click on addbutton
  8. Enter IIS APPPOOL\DefaultAppPool on the text box
  9. Click Ok button
  10. Ensure Read and Execute, List Folder and Content and Read Permissions are checked.
  11. Click Ok
  12. Click Ok
Sign up to request clarification or add additional context in comments.

4 Comments

Grant NTFS read permissions to application pool identity. How to do that??
Changing DefaultAppPool to LocalSystem worked. Now it is working.
Updated answer to give you instructions to add NTFS permissions. LocalSystem is too much powerfull account. It can do anything on your system. If I suggested you to change the account to SYSTEM account, I would receive a lot of down votes
Hi Thank you for details explanation. I tried that and gave required permission as suggested by you. But I am getting new error this time. fs.js:1690 binding.lstat(baseLong); ^ Error: EPERM: operation not permitted, lstat 'C:\Users\username' at Object.realpathSync (fs.js:1690:15) at toRealPath (module.js:170:13) at Function.Module._findPath (module.js:219:22) at Function.Module._resolveFilename (module.js:541:25) at Function.Module._load (module.js:470:25) at Function.Module.runMain (module.js:690:10)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.