Why does visual studio not make an exe file when using the windows service template and publishing it?

1.2k Views Asked by At

When publishing a console application, I have a lot of settings that I can change when deploying. I can choose between azure, clickonce, docker, normal folder and I am also able to choose the target runtime and the deployment mode.

But when using the windows service template for my project and I want to publish this, then the GUI looks totally different. I am not able to choose the settings that I had with the console application. I am not even able to choose the target runtime nor the deployment mode. Despite all that when I continue, the folder where my windows service is deployed doesn't contain an exe file of my application. It contains the setup.exe, but that is not what I want. I want the exe file of the windows service itself.

Does anyone have an idea why the settings are different and why it only gives a setup.exe?

Here below the settings of the publish console application as it should be. enter image description here

enter image description here

enter image description here

Here below the settings of the publish windows service template which looks totally different and with fewer settings. enter image description here enter image description here

2

There are 2 best solutions below

1
Nanmu Honery On

I don't understand your question very well, I suggest you review the files created by the publishing process.

1.In Solution Explorer, select Show All Files.

2.In the project folder, expand bin/Release/net6.0/publish.

If you are publishing console applications in visual studio, you can refer to this document, which has detailed publishing steps. https://learn.microsoft.com/en-us/dotnet/core/tutorials/publishing-with-visual-studio?pivots=dotnet-6-0#publish-the-app

3
Nanmu Honery On

After writing the window service class, do the following:

  1. Right click and select Add Installer

enter image description here

  1. The ProjectInstaller.cs file is added to the project, and the view in this file will automatically add two components serviceProcessInstaller1 and serviceInstaller1

enter image description here

3.Set the main properties of serviceInstaller1, ServiceName: the unique system service identifier, used when executing the command in the command, use to identify a window service. Set StartType, if it is Manual, start manually, stop by default, if it is Automatic, it will start automatically.enter image description here

4.Rebuild the project

5.Open Developer Command Prompt for Visual Studio with administrative credentials. In Developer Command Prompt for Visual Studio, navigate to the folder that contains your project's output (by default, the \bin\Debug subdirectory of your project). Enter the following command:installutil MyNewService.exe

6.Start and run the service. In Windows, open the Services desktop app. Press Windows+R to open the Run box, enter services.msc, and then press Enter or select OK.