简体   繁体   中英

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

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. 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Here below the settings of the publish windows service template which looks totally different and with fewer settings. 在此处输入图像描述 在此处输入图像描述

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://docs.microsoft.com/zh-cn/dotnet/core/tutorials/publishing-with-visual-studio?pivots=dotnet-6-0#publish-the-app

After writing the window service class, do the following:

  1. Right click and select Add Installer

在此处输入图像描述

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

在此处输入图像描述

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. 在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM