首页 > 解决方案 > 如何在批处理文件中运行 .net 核心应用程序

问题描述

我正在编写一个 .net 核心应用程序作为同步数据的作业运行。我已将 dotnet.exe 命令添加到 Path,当我直接在命令行中运行应用程序时,它运行良好。

我已经将应用程序部署到服务器并编写了一个批处理脚本(job.bat)来运行它,如下所示。

cd D:\the\folder\where\the\app\locate
dotnet TheJobToBeExecuted.dll

我想每 5 分钟运行一次作业,所以我使用下面的脚本将批处理添加到任务计划程序

schtasks /create /tn "Job" /tr "D:\the\folder\where\the\batch\locate\job.bat" /sc minute /mo 5

但这项工作并没有按预期工作。然后我如下更改job.bat以查看发生了什么。

cd D:\the\folder\where\the\app\locate
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 上运行该应用程序。

我错过了什么吗?谢谢。

标签: .net-corescheduled-tasks

解决方案


请在 powershell 中运行“get-command dotnet”并使用您的环境变量路径检查结果。

在此处输入图像描述


推荐阅读