Is it possible to schedule a .net core console application to run every day at a specific time using the Task Scheduler?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I think you will have to set the value for "Start in" while creating the task in task scheduler to your app folder, that is D:\Test\Test1. The app will run in this folder and should be able to find the appsettings file.
回答2:
Create a .bat file with the contents "dotnet myDLL.dll" in actions program/script -> "c:\yourpath\myBatFile.bat" Start in --> "c:\yourpath"
done.
回答3:
By default the app is going to look at the current folder for the existence of appsettings.json
because of the following:
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
replace the "appsettings.json"
with the full path to the file.