Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t启动dotnet核心进程。未能添加工具_C#_Batch File_Iis_.net Core - Fatal编程技术网

C# Can';t启动dotnet核心进程。未能添加工具

C# Can';t启动dotnet核心进程。未能添加工具,c#,batch-file,iis,.net-core,C#,Batch File,Iis,.net Core,我有一个在IIS中运行的web应用程序,它正在用.cmd文件启动一个进程。.bat文件启动dotnet核心应用程序 这在本地安装上运行良好,但在服务器上部署时,会出现以下错误: 无法将“C:\Users\Default.dotnet\tools”添加到路径环境中 变量将此目录添加到您的路径以使用随安装的工具 “dotnet工具安装” 已安装dotnet core和dotnet core sdk。如果我在命令提示符下运行.cmd文件,它在服务器上运行良好 我已经搜索过了,找不到任何关于如何解决这个

我有一个在IIS中运行的web应用程序,它正在用.cmd文件启动一个进程。.bat文件启动dotnet核心应用程序

这在本地安装上运行良好,但在服务器上部署时,会出现以下错误:

无法将“C:\Users\Default.dotnet\tools”添加到路径环境中 变量将此目录添加到您的路径以使用随安装的工具 “dotnet工具安装”

已安装dotnet core和dotnet core 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应用程序,但出现以下异常:
未能将“C:\Windows\system32\config\systemprofile\.dotnet\tools”添加到PATH环境变量。将此目录添加到您的路径,以使用随“dotnet工具安装”一起安装的工具。
因为我遇到了两个类似的异常,我想问题可能是文件夹的权限。 因此,我将服务帐户的修改权限添加到文件夹中
C:\Windows\system32\config\systemprofile
解决了问题。运行应用程序后,将创建以下新文件夹:
C:\Windows\System32\config\systemprofile\.dotnet
C:\Windows\System32\config\systemprofile\.nuget

然后,我在prod服务器上添加了相同的权限,但不包括文件夹的权限
C:\Users\Default


剩下的问题是,为什么两台服务器在不同路径中定位.dotnet文件夹?

请看一看,尤其是“.NET Core CLI试图将默认位置添加到PATH环境变量…”您还应该包括定义
.cmd
文件的代码,最好提供其内容。如果您不愿意这样做,请删除[]标记,在其当前状态下,它是不相关的,因为它没有在任何地方引用。分配给
runMyCmdPath
的字符串是什么?调用时的工作目录是什么?另外,当可以在.NET中以本机方式生成日期/时间戳时,为什么要使用批处理文件来生成日期/时间戳?(同样的问题是检查文件是否存在?请求输入?运行带参数的可执行文件?并移动文件?)。您不能在您的帐户下安装.NET Core全局工具,并期望该工具适用于所有用户(如应用程序池标识)。如果未检测到该用户帐户,请修改批处理文件以安装该工具。问题在于未安装工具,或者安装路径不正确。