使用 NAnt 在构建脚本中安装/卸载 Windows 服务

发布于 2024-09-13 05:16:52 字数 59 浏览 0 评论 0 原文

NAnt 是否能够使用 InstallUtil 实用程序或其他实用程序安装或卸载 Windows 服务?

Does NAnt have the ability to install or uninstall a windows service, using the InstallUtil utility or whatever else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

街道布景 2024-09-20 05:17:14

如果您在应用程序中使用 TopShelf 项目 来托管服务,您可以获得基于命令行的工具无需InstallUtil即可安装/删除服务。

ServiceName.exe 服务安装
ServiceName.exe 服务卸载

您可以直接运行该服务并获得一个漂亮的控制台窗口,您可以按 CTRL+C 停止它。您可以通过执行程序将其直接集成到 nant 或 msbuild 中。

If you use the TopShelf Project in your application to host your services, you can get command-line based tools for installing / removing the services without needing InstallUtil.

ServiceName.exe service install
ServiceName.exe service uninstall

And you can run the service directly and get a nice console window that you can CTRL+C to stop. You can integrate this directly into nant or msbuild by executing the program.

栀梦 2024-09-20 05:17:11

如果您的服务可以安装在不同的地方,您也可以使用 SC.EXE 通过其名称来卸载它,如下所示:

<property name="serviceName" value="Name of the service"/>
<exec program="sc" failonerror="false" verbose="true" if="${service::is-installed(serviceName,'.')}">
 <arg value="delete"/>
 <arg value="${serviceName}"/>
</exec>

If your service can be installed at different places, you can also uninstall it through its name using SC.EXE, as follows:

<property name="serviceName" value="Name of the service"/>
<exec program="sc" failonerror="false" verbose="true" if="${service::is-installed(serviceName,'.')}">
 <arg value="delete"/>
 <arg value="${serviceName}"/>
</exec>
纸伞微斜 2024-09-20 05:17:08

Nant 还是 MSBuild?自己运行 installutil 有什么问题 - 这就是您在 MSBuild 中所做的。 (一般来说,构建不会按照规则执行此类安装,因为通常您的构建应该能够在随机构建服务器上运行)。

另一个将 installutil 排除在外的选项是 像这样向您的服务添加自安装选项(通过查找自安装 Windows 服务来搜索更多信息)

Nant or MSBuild? What's the problem with just running installutil yourself - that's what you'd do in MSBuild. (In general, builds dont do the installs for things like this as rule as typically your build should be able to run on a random build server).

Another option, which would take installutil out of the equation is adding a self-install option to your service like this (have a search for more by looking for self install windows service)

帅哥哥的热头脑 2024-09-20 05:17:00

可以调用Nant的exec任务来调用InstallUtil并可以通过轻松安装或卸载服务的参数

 <target name="install-service">
    <exec program="${framework::get-framework-directory('net-2.0')}\InstallUtil.exe">
      <arg value="-i" />
      <arg value="/name=V1" />
      <arg value="C:\Service\SomeService.exe" />      
    </exec>
  </target>

You can call Nant's exec task to call InstallUtil and can pass parameters to install or uninstall a service easily

 <target name="install-service">
    <exec program="${framework::get-framework-directory('net-2.0')}\InstallUtil.exe">
      <arg value="-i" />
      <arg value="/name=V1" />
      <arg value="C:\Service\SomeService.exe" />      
    </exec>
  </target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文