Schedule a .Net Core console application on window

2019-04-21 04:37发布

问题:

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.