我有一个在IIS中运行的Web应用程序,该应用程序正在启动带有.cmd文件的进程。 .bat文件启动一个dotnet核心应用程序。
这在我的本地安装上工作正常,但是当我在服务器上部署时,出现以下错误:
无法将'C:\ Users \ Default.dotnet \ tools'添加到PATH环境 变量。将此目录添加到您的PATH中以使用随 “ dotnet工具安装”。
dotnet核心和dotnet核心sdk已安装。如果我从命令提示符下运行.cmd文件,则它在服务器上可以正常工作。
我已经搜索了,但是找不到任何解决方法的提示。
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();
}
编辑:.cmd文件代码:
@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
问题解决了。
我将Web应用程序安装在另一台服务器上,但出现以下异常:
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'.
因为我有2个类似的异常,所以我认为问题可能出在文件夹的权限上。
因此,我向该文件夹添加了对服务帐户的修改权限
C:\Windows\system32\config\systemprofile
解决了问题。运行该应用程序后,将创建以下新文件夹:
C:\Windows\System32\config\systemprofile\.dotnet
C:\Windows\System32\config\systemprofile\.nuget
然后我在产品服务器上添加了相同的权限,但对文件夹
C:\Users\Default
仍然存在的问题是为什么两台服务器在不同路径中定位.dotnet文件夹?
答案 0 :(得分:0)
在我重命名我的核心应用程序 dll 后遇到了类似的问题。发现我的应用程序 DLL 不再被找到以进行激活。所以我检查了 web.config
,结果忘记重命名 dll。
dotnet
本身不应该将任何文件写入 C:\Users\Default.dotnet\tools,因此如果可以找到应用程序,则不需要权限。