问题描述
我正在编写一个 .net 核心应用程序以作为同步数据的作业运行.我已将 dotnet.exe 命令添加到 Path,当我直接在命令行中运行应用程序时,它运行良好.
I am writing a .net core app to run as a job to sync data. I have added dotnet.exe command to Path and it works well When I run the app directly in command line.
我已将应用程序部署到服务器并编写了一个批处理脚本(job.bat)来运行它,如下所示.
I have deployed the app to server and write a batch script(job.bat) to run it as below.
cd D: hefolderwhere heapplocate
dotnet TheJobToBeExecuted.dll
我想每 5 分钟运行一次作业,所以我使用下面的脚本将批处理添加到任务计划程序
I want to run the job every 5 min, So I add the batch to Task Scheduler with the script below
schtasks /create /tn "Job" /tr "D: hefolderwhere heatchlocatejob.bat" /sc minute /mo 5
但是工作没有按预期工作.然后我修改 job.bat 如下,看看发生了什么.
But the job doesn't work as expected. Then I alter the job.bat as below to see what happened.
cd D: hefolderwhere heapplocate
dotnet TheJobToBeExecuted.dll
pause
消息显示如下
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
但是我已经安装了 dotnet 并将其添加到服务器上的路径中,我也可以直接在服务器 cmd 上运行该应用程序.
But I already install dotnet and added it to path on server, also I can run the app directly on server cmd.
我错过了什么吗?谢谢.
Am I missing something? Thanks.
推荐答案
我终于解决了这个问题.
Finally I have resolved this issue.
我的机器中有两个版本的 dotnet core 运行时.一个位于Program Files (x86)"文件夹中,另一个位于Program Files"目录中.它们都包含在路径环境中.
There are two versions of dotnet core runtime in my machine. One is in "Program Files (x86)" folder and another is in "Program Files" directory. They are both included in path environment.
我在路径环境中将c:Program Filesdotnet"移到了C:Program Files (x86)dotnet"之前.我工作正常.
I moved "c:Program Filesdotnet" ahead of the "C:Program Files (x86)dotnet" in path environment. I works fine.
这篇关于如何在批处理文件中运行 .net core 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!