使用 Chocolatey 安装 Windows 服务的 "correct" 方法是什么?

What is the "correct" way to use Chocolatey to install a Windows service?

我正在寻找有关如何打包我的 TopShelf 托管 Windows 服务以便通过 Chocolatey 分发的指导。目前 .nuspec 将 .exe 和所有 .dll 放入 \tools 文件夹,这意味着它们最终安装到 ProgramData\chocolatey\lib\our-service\tools。这似乎不对。实际上这不是问题,直到我注意到卸载记录了各种错误。这些都与 Chocolatey 试图备份文件有关,但由于服务正在 运行ning 而无法备份文件。 chocolateyuninstall。ps1 停止服务,但它不会 运行 直到备份尝试之后。

应用程序本身使用 ProgramData\MyCompany\MyApp 进行所有数据和日志记录。我也应该把二进制文件放在那里吗?还是 Program Files 更合适?如果这些位置之一是正确的,那么 chocolateyinstall.ps1 是将代码放置到 xcopy 二进制文件的合理位置吗?或者(我希望你说不)这甚至不是 Chocolatey 的有效使用吗?意思是,我应该接受并创建一个 MSI 供 Chocolatey 运行吗?

谢谢

Currently the .nuspec puts the .exe and all .dlls into the \tools folder, which means they end up installed to ProgramData\chocolatey\lib\our-service\tools. That just doesn't seem right. In fact it was not a problem until I noticed that the uninstall logs all sorts of errors. Which are all related to Chocolatey trying to back up the files but can't because they are in use because the service is running. The chocolateyuninstall.ps1 stops the service but it doesn't run till after the backup attempt.

我们正在添加一个 chocolateyBeforeModify.ps1 脚本,它将在 upgrade/uninstall - https://github.com/chocolatey/choco/issues/268 之前 运行。这应该在 0.9.10 中,将有助于使工作流程更顺畅。

目前,您必须在尝试升级或卸载之前停止 Chocolatey 之外的服务。

另一件需要考虑的事情是 Chocolatey 利用了 XDT (Xml Document Transformations),这意味着如果您为 xml 配置包含一个 *.install.xdt 文件,choco 不会简单地覆盖现有的文件。这使您可以在不覆盖任何用户配置的情况下升级包文件夹。但是,如果您要将文件复制到其他地方,您需要自己解决这个问题。

The application itself uses ProgramData\MyCompany\MyApp for all data and logging. Should I be putting the binaries there as well? Or is Program Files more appropriate?

我们还没有推荐的安装服务或设置网站/网络应用程序的方法。我们将来会为这两件事创建助手,届时我们会推荐这些途径,并就事情应该去哪里提出更好的建议。

更新20170324:我们现在在Chocolatey的商业版中有Install-ChocolateyWindowsService和其他服务相关的功能。

If one of these locations is correct, is chocolateyinstall.ps1 the logical place to put the code to xcopy the binaries?

自动化脚本是执行添加包位后需要执行的任何操作的合乎逻辑的位置。

Or (and i hope you say no) is this not even a valid use of Chocolatey? Meaning like, should I suck it up and create an MSI for Chocolatey to operate on?

创建服务和网站绝对是 Chocolatey 的有效用途。我建议除非需要,否则不要创建 MSI。这是一个相当复杂的过程,在大多数情况下(例如内部应用程序),感觉有点过头了。