mar*_*rko 9 msbuild teamcity windows-services msdeploy windows-server-2012
我想从运行团队城市的构建服务器部署Windows服务到最少的服务器配置到Windows Server 2012.
这样做的最佳方法之一是什么?
我通常使用直接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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5661 次 |
| 最近记录: |