MSBuild无法构建MSI。是否有Windows服务的替代品?

时间:2011-07-11 21:17:07

标签: c# .net windows deployment windows-services

我在Visual Studio中使用安装项目(.msi)。

安装步骤:

  1. 在Visual Studio中构建设置。
  2. 将设置复制到服务器。
  3. 运行安装程序。
  4. 在services.msc
  5. 中启动Windows服务

    更新步骤:

    1. 在Visual Studio中构建设置。
    2. 将设置复制到服务器。
    3. 在services.msc
    4. 中停止Windows服务
    5. 卸载Windows服务。
    6. 运行安装程序。
    7. 在services.msc
    8. 中启动Windows服务

      我的构建服务器仅使用msbuild构建,无法构建安装项目(.msi)。

      我必须在构建服务器上安装Visual Studio,还是有更好的选择?

2 个答案:

答案 0 :(得分:4)

使用installutil.exe更容易,更快......您可以使用installutil /u myservice.exe在服务器上停止和卸载服务,删除旧文件,复制新文件并使用installutil myservice.exe重新启动 - 安装你的服务......

答案 1 :(得分:1)

为此,我使用Phil Wilsons ReadSvcXml.exe工具,当在安装项目上作为后期构建事件运行时,更新安装程序msi文件,其中包含特定信息,可以重定向服务(即包括添加依赖项,以在卸载时停止服务,注册它等)。这是在安装完成后自动启动服务的最简单,最可靠的方法。

例如,安装项目的后期构建事件是: .. \ ReadSvcXml.exe MyApplication.msi .. \ ServiceSetup.xml

ServiceSetup.xml的位置如下:

<ServiceData>
  <FileName>MyServiceHost.exe</FileName>
  <ServiceInstall>
    <Id>ServiceInstallColumn</Id>
    <Name>GatewayServer</Name>
    <DisplayName>Company MyServer</DisplayName>
    <ServiceType>ownprocess </ServiceType> <!-- or shareprocess-->
    <Interactive>no</Interactive>
    <Start>auto</Start> <!--auto demand or disabled-->
    <ErrorControl>
    <!--ignore normal critical -->
    normal
    </ErrorControl>
    <Dependencies>MSSQLSERVER</Dependencies>
    <Description>MyServer for blar blar blar</Description>
  </ServiceInstall>
  <ServiceControl>
    <Name>MyServerName</Name>
    <Id>MyServerId</Id>
    <!-- install, uninstall or both-->
    <Start>install</Start>
    <Stop>both</Stop>
    <Remove>uninstall</Remove>  
    <Wait>no</Wait> <!-- no yes -->
  </ServiceControl>
</ServiceData>

可以在这里下载SvcInstall:
download svcinstall bin and source