Skip to content

Instantly share code, notes, and snippets.

@cowlike
Last active December 21, 2019 18:37
Show Gist options
  • Save cowlike/774522c94265a6e3fc87859940343caf to your computer and use it in GitHub Desktop.
Save cowlike/774522c94265a6e3fc87859940343caf to your computer and use it in GitHub Desktop.
Steps for creating a Windows service using .NET Core 3
$ dotnet new sln -o WindowsService
The template "Solution File" was created successfully.
$ cd WindowsService/
$ dotnet new worker -n Main -o Main
The template "Worker Service" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on Main\Main.csproj...
Restore completed in 555.33 ms for C:\data\workspaces\ms\WindowsService\Main\Main.csproj.
Restore succeeded.
$ dotnet new xunit -n Tests -o Tests -lang f#
The template "xUnit Test Project" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on Tests\Tests.fsproj...
Restore completed in 4.65 sec for C:\data\workspaces\ms\WindowsService\Tests\Tests.fsproj.
Restore succeeded.
jkrup@DESKTOP-F12AHG6 MINGW64 /c/data/workspaces/ms/WindowsService
$ dotnet sln add Tests/Tests.fsproj Main/Main.csproj
Project `Tests\Tests.fsproj` added to the solution.
Project `Main\Main.csproj` added to the solution.
jkrup@DESKTOP-F12AHG6 MINGW64 /c/data/workspaces/ms/WindowsService
$ dotnet add Tests/Tests.fsproj reference Main/Main.csproj
Reference `..\Main\Main.csproj` added to the project.
$ dotnet add Main/Main.csproj package Microsoft.Extensions.Hosting.WindowsServices --version 3.1.0
## $ dotnet publish -o c:\code\workerpub
## $ sc create workertest binPath=c:\code\workerpub\WorkerTest.exe
## $ sc delete workertest
# What worked!
$ dotnet publish -r win7-x86 -c Release -o /c/apps/testapps/workertest -p:PublishSingleFile=True -p:PublishTrimmed=True -p:UseAppHost=True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment