C# ClickOnce 部署 Windows 服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/460118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 04:15:12  来源:igfitidea点击:

ClickOnce deploy a Windows Service?

c#visual-studio-2008windows-servicesclickonce

提问by NoizWaves

Is it possible to deploy a Windows Service using ClickOnce? If so, how do you achieve this?

是否可以使用 ClickOnce 部署 Windows 服务?如果是这样,你如何实现这一目标?

Currently we have to use a Deployment project, and the installation process could be simplified greatly by using ClickOnce.

目前我们必须使用一个Deployment项目,使用ClickOnce可以大大简化安装过程。

回答by Marc Gravell

AFAIK you can't really use ClickOnce end-to-end to deploy a service; there are issues with both the file locations (ClickOnce installs into a user's profile) and installation (ClickOnce is largelyside-effect free).

AFAIK 你不能真正使用 ClickOnce 端到端来部署服务;文件位置(ClickOnce 安装到用户的配置文件中)和安装(ClickOnce基本上没有副作用)都存在问题。

You can, however, write a service as an exe that can self-install/uninstall from the services list, like so; basically, you write it as as a console exe and handle some command line args, using AssemblyInstallerto [un]install from the current assembly. Another advantage is that the same approach can be used to help debugging, since you can run it from the command line.

但是,您可以将服务编写为可以从服务列表中自行安装/卸载的 exe,如下所示;基本上,您将其编写为控制台 exe 并处理一些命令行参数,使用AssemblyInstaller[un] 从当前程序集安装。另一个优点是可以使用相同的方法来帮助调试,因为您可以从命令行运行它。

回答by Guilherme de Jesus Santos

Instead of ClickOnce, I like to use the approach using Inno Setup, like in here https://stackoverflow.com/a/1450051/396200

而不是 ClickOnce,我喜欢使用 Inno Setup 的方法,就像在这里https://stackoverflow.com/a/1450051/396200

You have more control over what and how will be copied and executed.

您可以更好地控制复制和执行的内容和方式。

As Marc Gravell said in his answer, I create a exe that self install my service, and then use Inno Setup to pack and deploy it. After Inno setup installed, it automatically run the exe and then my exe install my service.

正如 Marc Gravell 在他的回答中所说,我创建了一个自我安装我的服务的 exe,然后使用 Inno Setup 来打包和部署它。安装 Inno setup 后,它会自动运行 exe,然后我的 exe 安装我的服务。