[英]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.
我可以在 azure、clickonce、docker、普通文件夹之间进行选择,我还可以选择目标运行时和部署模式。
But when using the windows service template for my project and I want to publish this, then the GUI looks totally different.但是当为我的项目使用 windows 服务模板并且我想发布它时,GUI 看起来完全不同。 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.
尽管如此,当我继续时,部署我的 windows 服务的文件夹不包含我的应用程序的 exe 文件。 It contains the setup.exe, but that is not what I want.
它包含 setup.exe,但这不是我想要的。 I want the exe file of the windows service itself.
我想要 windows 服务本身的 exe 文件。
Does anyone have an idea why the settings are different and why it only gives a setup.exe?有谁知道为什么设置不同以及为什么它只提供 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.下面是发布 windows 服务模板的设置,它看起来完全不同且设置更少。
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. 1.在解决方案资源管理器中,select 显示所有文件。
2.In the project folder, expand bin/Release/net6.0/publish. 2.在项目文件夹中,展开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.如果你是在visual studio中发布控制台应用,可以参考这个文档,里面有详细的发布步骤。 https://docs.microsoft.com/zh-cn/dotnet/core/tutorials/publishing-with-visual-studio?pivots=dotnet-6-0#publish-the-app
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:写入 window 服务 class 后,执行以下操作:
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. 3.设置serviceInstaller1的主要属性,ServiceName:唯一的系统服务标识符,在命令中执行命令时使用,用于标识一个window服务。 Set StartType, if it is Manual, start manually, stop by default, if it is Automatic, it will start automatically.
设置StartType,如果是Manual,手动启动,默认停止,如果是Automatic,则自动启动。
4.Rebuild the project 4.重建项目
5.Open Developer Command Prompt for Visual Studio with administrative credentials. 5.使用管理凭据打开 Visual Studio 的开发人员命令提示符。 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).
在 Visual Studio 的开发人员命令提示符中,导航到包含项目 output 的文件夹(默认情况下,项目的 \bin\Debug 子目录)。 Enter the following command:
installutil MyNewService.exe
输入以下命令:
installutil MyNewService.exe
6.Start and run the service. 6.启动并运行服务。 In Windows, open the Services desktop app.
在 Windows 中,打开服务桌面应用程序。 Press Windows+R to open the Run box, enter services.msc, and then press Enter or select OK.
按 Windows+R 打开运行框,输入 services.msc,然后按 Enter 或 select 确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.