Is it possible to schedule a .net core console application to run every day at a specific time using the Task Scheduler?
-
3yes, it is possible. Describe what you have tried so far and what is the current problem. Right now your question is off-topic. – Set Apr 24 '17 at 18:29
-
My console application is in the folder D:\Test\Test1. I can run the program from within this folder: dotnet MyApp.dll. However I am not sure how to run it from outside the published folder. I get an error when I try to run it from outside like this : dotnet D:\Test\Test1\MyApp.dll. The error says it cannot find appsettings.json. What is the right syntax to run a .net core console app from outside the published folder? – Sandhya Apr 24 '17 at 18:45
-
You then need to show the code where you define that your program should read appsettings.json – Scott Chamberlain Apr 24 '17 at 19:09
-
2Why down voted? Everyone may not know the answers which are trivial to you. – Hemant Sakta Sep 07 '17 at 20:51
6 Answers
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.

- 656
- 7
- 6
-
1
-
@Prashant - When I created console app using asp.net Core 2.0 there is no `.exe` file generated in bin/debug folder – prog1011 Oct 23 '18 at 09:58
-
See if this link helps you. https://stackoverflow.com/questions/44038847/vs2017-compile-netcoreapp-as-exe – Prashant Mothukuri Oct 31 '18 at 17:31
-
.netcore 3.1 console app with window server 2016 task scheduler, for a more detailed solution, check out breadtruck's answer: https://serverfault.com/questions/863405/net-core-console-app-fails-from-task-scheduler-with-0xc0000005 – made_it_ma Mar 29 '21 at 17:44
-
Yes, its possible. But theres a trick. For some reason task scheduler mandates full path and filename for hosting process, so you need to enter in the "Program/Script" "C:\Program Files\dotnet\dotnet.exe". Confirmed this on Windows Server 2012 R2 with latest patches. .Net Core program goes into arguments box, no need for full path there. However .Net core program location path is required in "Start in". At least in cases when program is expecting to find some files from its location.

- 422
- 5
- 10
-
1IMHO this is the most complete answer. I realize it came along well after the others, but it has the details that aren't fully clear in the other answers. Especially for people like me who are used to the "old way" of scheduling console applications. – Mike Devenney Oct 18 '19 at 12:50
-
1Start In for the win.... couldn't find my appsettings.json file.... :-) Set Start In and worked. – Kevin LaBranche Jun 16 '21 at 17:32
-
i have similar issue for 2 hours trying to get an answer for this.
All you just need to do for your .Net Core Console App!
- Go to your Task Scheduler
- Go to the tab menu and click on Actions
- Click on New/Edit
- select the dropdown: Action: Start a program
- program/script: "C:\Document\MyConsoleApp.exe"
------> note very important. put in your app path where you have your console app because your task scheduler will have to read to configurations - Start in (optional): C:\Document\
This solved my problem.
Cheers Guys!!!

- 131
- 1
- 5
-
1Thank you so much. This piece of adding path of the folder was something that I was missing. Thank you so much. – Ashish Deora May 19 '23 at 13:11
Create a .bat file with the contents "dotnet myDLL.dll" in actions program/script -> "c:\yourpath\myBatFile.bat" Start in --> "c:\yourpath"
done.

- 31
- 1
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.

- 2,094
- 1
- 18
- 28
-
Actually shouldn't the `.SetBasePath(env.ContentRootPath)` make it so it does not use the current folder. but actually looks at the base path of the application? I bet the problem is the OP is just missing that line. – Scott Chamberlain Apr 24 '17 at 21:44
-
@ScottChamberlain it depends on how he has configured his webhostbuilder I think. By default, the webhost builder uses `.UseContentRoot(Directory.GetCurrentDirectory())` I believe... so wouldn't that make setbasepath to be incorrect as well? – Muqeet Khan Apr 24 '17 at 22:12
-
1Thanks for the suggestions! I was just not setting the 'start in' folder in the Task scheduler - that was the problem. And its a she btw.. – Sandhya Apr 24 '17 at 22:16
-
-
Voted down. The answer provided in no way answers the OP's question. – Mike Devenney Oct 18 '19 at 12:48
Faced the same issue and it ate my hours, solved it by not publishing the project but only by building it. after building the project i just took the content of
MyProject\bin\Release\net5.0
and placed it in
F:\MyFolder
then created a Task in Scheduler, with in Action => Program/script
MyProject.exe
and Start in
F:\MyFolder\MyProject\bin\Release\net5.0
bingo...

- 1,269
- 6
- 14