Tuesday, April 9, 2019

how to setup a schedule task for DotNet Core Console App?

When we publish the dotnet core project either from publish command in visual studio, or use the command line dotnet publish -c Release -r win10-x64 in CMD window.

after we execute the publish command. we can have the following message from the Visual Studio Output Windows

1>------ Publish started: Project: ConsoleAppEncryptDecrypt, Configuration: Release Any CPU ------
1>ConsoleAppEncryptDecrypt -> C:\Users\ddeng\Source\Repos\ConsoleAppEncryptDecrypt\ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1\ConsoleAppEncryptDecrypt.dll
1>ConsoleAppEncryptDecrypt -> C:\Users\ddeng\Source\Repos\ConsoleAppEncryptDecrypt\ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1\publish\
1>ConsoleAppEncryptDecrypt was published successfully to bin\Release\netcoreapp2.1\publish\
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

and we can see the compile output in this folder




when we schedule a task with action from this folder. we can use both paths

ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1

ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1\publish

the schedule task can run succesfully without an error.

However when we move the production server,

if we use this path  ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1, the schedule task completed with an error code  3762504530.

the root cause of this issue is that the hosting server do not have the same environment as my local desktop. I have to use the publish folder (ConsoleAppEncryptDecrypt\bin\Release\netcoreapp2.1\publish) which will copy all necessary DLL to folder, in order to run the dotnet core Console app.

No comments:

Post a Comment