Msbuild 从team city部署windows服务
我想以最低服务器配置将运行team city的构建服务器中的windows服务部署到windows server 2012Msbuild 从team city部署windows服务,msbuild,windows-services,teamcity,msdeploy,windows-server-2012,Msbuild,Windows Services,Teamcity,Msdeploy,Windows Server 2012,我想以最低服务器配置将运行team city的构建服务器中的windows服务部署到windows server 2012 做到这一点的最佳方法是什么?我们使用的msdeploy包定义如下: <sitemanifest> <runCommand path='presync.cmd' waitInterval='30000'/> <dirPath path='$winSvc' /> <runCommand path='postsync.cmd'
做到这一点的最佳方法是什么?我们使用的msdeploy包定义如下:
<sitemanifest>
<runCommand path='presync.cmd' waitInterval='30000'/>
<dirPath path='$winSvc' />
<runCommand path='postsync.cmd' waitInterval='30000'/>
</sitemanifest>
postsync.cmd
:
net stop Svc
installUtil /u /name=Svc $destPath\Svc.exe
installUtil /name=Svc $destPath\Svc.exe
net start Svc
所有文件都是由powershell脚本生成的。我通常使用直接powershell或msbuild来实现这一点。我尽量避免使用片状的msdeploy。 因此,在msbuild中,您可以使用非常方便的msbuild扩展包,因此,假设您可以将文件复制到目标目标(Robocopy非常方便),那么剩下的工作就可以完成了:
<Project ToolsVersion="4.0" DefaultTargets="InstallService" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="..\packages\MSBuild.Extension.Pack.1.2.0\lib\net40\MSBuild.ExtensionPack.dll"
TaskName="MSBuild.ExtensionPack.Computer.WindowsService"/>
<PropertyGroup>
<MachineName Condition="$(MachineName)==''"></MachineName>
<ServiceName Condition="$(ServiceName)==''"></ServiceName>
<ServicePath Condition="$(ServicePath)==''"></ServicePath>
<User Condition="$(User)==''"></User>
<Password Condition="$(Password)==''"></Password>
<SuppressStart Condition="$(SuppressStart)==''"></SuppressStart>
</PropertyGroup>
<Target Name="CheckProperties" BeforeTargets="StopService">
<Message Text="MachineName: $(MachineName)"/>
<Message Text="ServiceName: $(ServiceName)"/>
<Message Text="ServicePath: $(ServicePath)"/>
<Message Text="User : $(User)"/>
<Message Text="SuppressStart : $(SuppressStart)"/>
</Target>
<Target Name="StopService" BeforeTargets="InstallService">
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="CheckExists"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)">
<Output TaskParameter="Exists" PropertyName="DoesExist"/>
</MSBuild.ExtensionPack.Computer.WindowsService>
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="Stop"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)"
Condition="$(DoesExist)=='True'">
</MSBuild.ExtensionPack.Computer.WindowsService>
</Target>
<Target Name="StartService" AfterTargets="InstallService">
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="CheckExists"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)">
<Output TaskParameter="Exists" PropertyName="DoesExist"/>
</MSBuild.ExtensionPack.Computer.WindowsService>
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="Start"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)"
Condition="$(DoesExist)=='True' And $(SuppressStart)=='False'"
RetryAttempts="20">
</MSBuild.ExtensionPack.Computer.WindowsService>
<Message Text="Service $(ServiceName) set not to start" Condition="$(SuppressStart)=='True'" Importance="High" />
</Target>
<Target Name="InstallService">
<PropertyGroup>
<ServiceExeExists Condition="Exists('$(ServicePath)')">True</ServiceExeExists>
</PropertyGroup>
<Message Text="Installing $(ServicePath) %(ServiceName.Identity)" Importance="high"/>
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="CheckExists"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)">
<Output TaskParameter="Exists" PropertyName="DoesExist"/>
</MSBuild.ExtensionPack.Computer.WindowsService>
<Message Text="Installed $(ServiceName) $(ServicePath) for $(User) and $(Password)" Importance="high"/>
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="Install"
ServiceName="$(ServiceName)"
User="$(User)"
Password="$(Password)"
ServicePath="$(ServicePath)"
MachineName="$(MachineName)"
Condition="!$(DoesExist)"/>
<MSBuild.ExtensionPack.Computer.WindowsService
TaskAction="SetAutomatic"
ServiceName="$(ServiceName)"
MachineName="$(MachineName)"
Condition="!$(DoesExist)"/>
<Warning Text="%(ServiceName.Identity) service already exists" Condition="$(DoesExist)"/>
</Target>
</Project>
真的
如果等待时间不够长怎么办?如果没有太多使用msdeploy的经验(使用过几次,但从未真正了解它是如何“在引擎罩下”工作的),我必须承认我也觉得它有点古怪。不过,这只是一些观点,但我最终使用了带有复制命令和几个bat文件的msbuild。您的解决方案看起来更加健壮,但正如您自己所说,需要某种文件共享访问。在我们的情况下,我们做到了!所以这个解决方案有效&我将把它标记为一个答案。您知道“卸载服务”或“停止服务”将等待服务正常停止多长时间吗?永远?嗨,Marko,很高兴我能帮上忙,从在线文档中可以看到retryattempts属性默认为60。