Install/Uninstall a Windows Service in a build script with NAnt

為{幸葍}努か 提交于 2019-12-11 13:19:50

问题


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


回答1:


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>



回答2:


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)




回答3:


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>



回答4:


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.



来源:https://stackoverflow.com/questions/3416872/install-uninstall-a-windows-service-in-a-build-script-with-nant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!