我希望将运行团队城市的构建服务器中的Windows服务部署到Windows Server 2012,并使用最少的服务器配置。
最好的方法之一是什么?
答案 0 :(得分:5)
我通常使用直接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>
答案 1 :(得分:1)
我们正在使用这样定义的msdeploy包:
<sitemanifest>
<runCommand path='presync.cmd' waitInterval='30000'/>
<dirPath path='$winSvc' />
<runCommand path='postsync.cmd' waitInterval='30000'/>
</sitemanifest>
presync.cmd
:
net stop Svc
installUtil /u /name=Svc $destPath\Svc.exe
postsync.cmd
:
installUtil /name=Svc $destPath\Svc.exe
net start Svc
所有文件都是由powershell脚本生成的。