2

I am building a small windows service using .net5 and "Worker Service" template. I've already added the Hosting.WindowsService dependencies to make it run under Windows.

I can correctly install/uninstall and start/stop my service by using windows built-in "sc.exe" tool via command line. (I've followed the official guide on Microsoft Dev blog)

I would like to build an MSI package to redistribute it and automatically install/uninstall it with current user privileges (like old ServiceInstaller did with .net Framwework services)

I read a lot of posts on SO about MSI packages builder, like InstallShield, Advanced Installer, but I'm wondering if there is a much simpler solution. I remember using Visual Studio Installer Project , that automatically detects ServiceInstaller class in my projects and install correctly the service. I can't use it now because in .net Core and .net5 , services are built differently.

I also read that some developers adds the possibility to install the service though the service itself, by adding command line arguments and using ServiceController and ServiceInstaller classes, but again I can't use those in .net5

The ultimate possibility would be rollback my service to .netfx 4.8 , but I'd rather not.

Any suggestion?

Thanks!

UPDATE

I've tried using InnoSetup , and I put these directives in Run an UninstallRun sections, and seems to work. I know this is a workaround, but is there a better way to do this?

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
Filename: {sys}\sc.exe; Parameters: "create TestService start= auto binPath= ""{app}\{#MyAppExeName}""" ; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "description TestService ""My Test Service"""; Flags: runhidden

[UninstallRun]
Filename: {sys}\sc.exe; Parameters: "stop TestService" ; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "delete TestService" ; Flags: runhidden
Simon
  • 123
  • 1
  • 7
  • [Please have a look here](https://stackoverflow.com/q/69841738/129130). Please make sure to check those further links. That's where the real information is - the answer is just a summary. – Stein Åsmul Nov 09 '21 at 15:27

0 Answers0