如何使用Team Build 2010部署Windows Service项目 [英] How to deploy Windows Service projects with Team Build 2010

查看:193
本文介绍了如何使用Team Build 2010部署Windows Service项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS2010解决方案,其中包括几个Windows服务项目。我需要在Team Build 2010中部署这些服务,并且Windows服务必须部署在几台Windows Server计算机上。



我该怎么做

解决方案

您可以有条件地调用 SC.exe 命令从您的Windows服务项目文件(* .csproj)在远程计算机上安装Windows服务。 p>

这是一个例子:

 < PropertyGroup> 
< DeployWinService> false< / DeployWinService>
< WinServiceName> MyService< / WinServiceName>
< TargetWinServiceHost Condition ='$(TargetWinServiceHost)'==''> localhost< / TargetWinServiceHost>
< / PropertyGroup>

< Target Name =AfterCompile>
< CallTarget Targets =PublishWinService/>
< / Target>

< Target Name =PublishWinService
Condition ='$(DeployWinService)'=='true'>
< Exec Command =sc stop $(WinServiceName)ContinueOnError =true/>
< Exec Command =sc \\ $(TargetWinServiceHost)create $(WinServiceName)binpath ='$(OutDir)\ $(AssemblyName).exe'start = auto/>
< / Target>

这里我们定义自定义MSBuild属性 DeployWinService TargetWinServiceHost ,用于控制是否在编译后安装Windows Service项目的输出以及哪个机器。 WinServiceName 属性只是指定Windows服务在目标计算机上具有的名称。



在你的构建定义,您必须在中显式设置 DeployWinService TargetWinServiceHost 属性高级部分的MSBuild参数字段:

  / p:DeployWinService = true; TargetWinServiceHost = MACHINENAME 

相关资源:




I have a VS2010 solution, which includes several Windows Service projects. I need to deploy these services as part of a build in Team Build 2010, and the Windows Services have to be deployed on several Windows Server machines.

How can I do this?

解决方案

You could conditionally invoke the SC.exe command from your Windows Service project file (*.csproj) to install the Windows Service on a remote machine.

Here's an example:

<PropertyGroup>
  <DeployWinService>false</DeployWinService>
  <WinServiceName>MyService</WinServiceName>
  <TargetWinServiceHost Condition="'$(TargetWinServiceHost)' == ''">localhost</TargetWinServiceHost>
</PropertyGroup>

<Target Name="AfterCompile">
  <CallTarget Targets="PublishWinService" />
</Target>

<Target Name="PublishWinService"
        Condition="'$(DeployWinService)' == 'true'">
  <Exec Command="sc stop $(WinServiceName)" ContinueOnError="true" />
  <Exec Command="sc \\$(TargetWinServiceHost) create $(WinServiceName) binpath= '$(OutDir)\$(AssemblyName).exe' start= auto" />
</Target>

Here we are defining the custom MSBuild properties DeployWinService and TargetWinServiceHost that are used to control whether the output of the Windows Service project will be installed after compilation and to which machine. The WinServiceName property simply specifies the name that the Windows Service will have on the target machine.

In your build definition you'll have to explicitly set the DeployWinService and TargetWinServiceHost properties in the MSBuild Arguments field of the Advanced section:

/p:DeployWinService=true;TargetWinServiceHost=MACHINENAME

Related resources:

这篇关于如何使用Team Build 2010部署Windows Service项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆