Simon Jonasson
Simon Jonasson

Reputation: 11

Can't start dotnet core process. Failed to add tools

I have a web application running in IIS that is starting a process with a .cmd file. The .bat file starts a dotnet core application.

This works fine on my local installation but when I deploy on a server I get the following error:

Failed to add 'C:\Users\Default.dotnet\tools' to the PATH environment variable. Add this directory to your PATH to use tools installed with 'dotnet tool install'.

dotnet core and dotnet core sdk are installed. It works fine on the server if I run the .cmd file from a command prompt.

I have searched and can't find any hints on how to solve this.

      private void RunMyCmd(string runMyCmdPath)
        {
            int exitCode;
            ProcessStartInfo processInfo;
            Process process;

            processInfo = new ProcessStartInfo(runMyCmdPath);
            processInfo.CreateNoWindow = true;
            processInfo.UseShellExecute = false;
            // *** Redirect the output ***
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardInput = true;

            process = Process.Start(processInfo);

            StreamWriter writer = process.StandardInput;
            //string output = reader.ReadToEnd();
            writer.WriteLine("a");

            // Write the redirected output to this application's window.
            //  Console.WriteLine(output);
            string output1 = process.StandardOutput.ReadToEnd();
            string error = process.StandardError.ReadToEnd();

            process.WaitForExit();

            // *** Read the streams ***
            // Warning: This approach can lead to deadlocks, see Edit #2


            exitCode = process.ExitCode;

            if (exitCode != 0)
                errorLogger.Error(string.Format("RunMyCmd: ExitCode({0}) - {1}", exitCode, error));

            process.Close();

        }

Edit: .cmd-file code:

@echo off
rem switch to on to test
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
rem echo datestamp: "%datestamp%"
rem echo timestamp: "%timestamp%"
rem echo fullstamp: "%fullstamp%"
rem  Go to script's directory
cd %~dp0

rem  Read filenames if needed
set rules=%~dp0rules.json
set testcases=%~dp0testcases.csv

if not exist %rules% (
    echo file not found. Type in full file name and Enter
    set /p rules="Rules file: "
)
if not exist %rules% (
    echo We did not find rules file: %rules%
    exit /B 1
)

if not exist %testcases% (
    echo testcases not found. Type in full file name and Enter
    set /p testcases="Testcases file: "
)
if not exist %testcases% (
    echo We did not find testcase file: %testcases%
    exit /B 1
)

rem Create filename for results csv
set filename="results_%fullstamp%.csv"
rem Run
cd AppFolder
dotnet run --no-build %rules% %testcases% %filename%
move %filename% ../results/
PAUSE

Problem solved.

I installed the Web application on another server and got the following exception: Failed to add 'C:\Windows\system32\config\systemprofile\.dotnet\tools' to the PATH environment variable. Add this directory to your PATH to use tools installed with 'dotnet tool install'. Because I got 2 similar exceptions I figured the problem might be with permissions on the folder. So I added modify permissions for the service account to the folder C:\Windows\system32\config\systemprofile Which solved the problem. After running the app these new folders was created: C:\Windows\System32\config\systemprofile\.dotnet C:\Windows\System32\config\systemprofile\.nuget

I then added the same permissions on my prod server but for the folder C:\Users\Default

The question that remains is why two servers are locating .dotnet folders in different paths?

Upvotes: 1

Views: 1865

Answers (1)

Trishna Pattanaik
Trishna Pattanaik

Reputation: 31

Got similar issue after I renamed my core application dll. Figured my application DLL isn't being found for activation anymore. So i checked inside web.config turns out forgot to rename dll.

dotnet itself should not be writing any files to C:\Users\Default.dotnet\tools, so the permissions should not be necessary provided the application can be found.

Upvotes: 3

Related Questions