MUKARRAM JAVID · Programing · 2 years ago

Create Windows Service in .Net core 3.1+

Create Windows Service in .Net core 3.1+

1. Create New project of type "Console App (.NET core)".

2. Go to Package Manager Console or from NuGet packages and write the command:

        Install-Package Microsoft.Windows.Compatibility

3. Create JobExecuter.cs which executes methods of Crawler.cs

        // Crawler & Jo Executer is custom classes

4. Create NameOfService.cs which is inherited by ServiceBase

5. Write ServicesToRun code in Program.cs

6. Rebuild the solution in Release mode

7. Run command prompt As Administrator

8. Go to path of project.

9. Create .exe of project with command:

        dotnet publish –configuration release

10. Create windows service using command:

        sc create NameOfService binpath="[Path Destination]\bin\Release\netcoreapp2.2\win10-x64\publish\FanChallengeCricParserService.exe"

        You should get the response : [SC] CreateService SUCCESS

        A service should have been created which can be verified in Control Panel -> Administrative Tools -> Services.

11. To start service from command line:

        sc start FanChallengeCricParserService

12. To stop service from command line:

        sc stop FanChallengeCricParserService

13. To remove the service from command line:

        sc delete FanChallengeCricParserService

© 2024 - Built with Mukarram