简体   繁体   English

为什么Visual Studio在使用windows服务模板并发布时不制作exe文件?

[英]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 后,执行以下操作:

  1. Right click and select Add Installer右键单击并 select 添加安装程序

在此处输入图像描述

  1. The ProjectInstaller.cs file is added to the project, and the view in this file will automatically add two components serviceProcessInstaller1 and serviceInstaller1项目中添加ProjectInstaller.cs文件,该文件中的视图会自动添加两个组件serviceProcessInstaller1和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. 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.

相关问题 在Visual Studio 2013上发布Windows服务 - Publishing windows service on Visual studio 2013 Visual Studio Windows 服务 c# exe 文件丢失 - Visual Studio Windows Service c# exe file missing 启动Windows服务时(在Visual Studio中创建的exe)错误1053 - Error 1053 when starting a Windows Service (exe created in Visual Studio) 如何为visual studio 2012中创建的Windows服务创建EXE设置文件 - How to create EXE setup file for windows service created in visual studio 2012 发布时Visual Studio更改文件格式存在问题 - Trouble with visual studio changing file format when publishing FileSystemWatcher 作为使用 Visual Studio 2019 的 Windows 服务 - FileSystemWatcher as a Windows Service using Visual Studio 2019 Visual Studio 2015不显示exe文件的树结构 - Visual Studio 2015 does not show the tree structure of an exe file 使用process.start()运行cmd.exe时如何引用存储在visual studio项目资源中的exe文件 - How to reference an exe file stored in visual studio project resource when running cmd.exe using process.start() 为什么Visual Studio 2017会发布整个解决方案? - Why Visual studio 2017 is publishing entire solution? 使用 dotnet 发布时设置 exe 文件版本 - Setup exe file version when publishing with dotnet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM