【问题标题】:MSBuild can't build an MSI. Are there alternatives for a Windows service?MSBuild 无法构建 MSI。 Windows 服务是否有替代方案?
【发布时间】:2011-07-11 21:17:07
【问题描述】:
我在 Visual Studio 中使用安装项目 (.msi)。
安装步骤:
- 在 Visual Studio 中构建设置。
- 将设置复制到服务器。
- 运行设置。
- 在 services.msc 中启动 Windows 服务
更新步骤:
- 在 Visual Studio 中构建设置。
- 将设置复制到服务器。
- 在 services.msc 中停止 Windows 服务
- 卸载 Windows 服务。
- 运行设置。
- 在 services.msc 中启动 Windows 服务
我的构建服务器仅使用 msbuild 构建,无法构建安装项目 (.msi)。
我必须在我的构建服务器上安装 Visual Studio,还是有更好的替代方案?
【问题讨论】:
标签:
c#
.net
windows
deployment
windows-services
【解决方案1】:
使用 installutil.exe 更加简单快捷...您可以使用installutil /u myservice.exe 停止和卸载服务器上的服务,删除旧文件,复制新文件并使用installutil myservice.exe 重新安装您的服务...
【解决方案2】:
为此,我使用 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