首页 > 代码库 > TFS Build Definition And Auto Deploy
TFS Build Definition And Auto Deploy
一台build machine上一般只有一个build service[对应一个build controller]来serve一个team project collection,但又workaround来实现多个controller在一台机器上的共存,参考这里。
说一说自动化build和自动化部署:
1.创建Build Definition[build serivce的账号必须有drop folder的写权限,就是Build Definition\Build Defaults\Staging location下的UNC path如\\10.1.1.16\DropFolder]。
注意:a)之前在创建好然后trigger后老是挂掉,原因是版本引用问题,参考这篇mark。
b)在Process中Required->items to build指定要build的solution or project。
2.在build definition的Process->Advanced->MSBuild Arguments添加如下参数以完成build后的自动部署(参数之间用空格分开):
/p:DeployOnBuild=True
/p:Configuration=Debug //此处的Configuration可以在configuration manager中自己创建;每次发布都会做文件的全部替换,不希望web.config文件(此处以web项目为例)被 //替换的话,其实一般就是数据库的链接字符串和一些appsettings,可以在Web.Debug.Config中做一些设置,详见第三条;
/p:SkipExtraFilesOnServer=true
/p:DeployTarget=MSDeployPublish
/p:MSDeployPublishMethod=RemoteAgent //即使用web deploy的方法,如果用其他的比如IIS自带的WMSVC的话,相应参数另行设置;还有WebDeployPackage;
/p:AllowUntrustedCertificate=True
/p:CreatePackageOnPublish=true
/p:DeployIISAppPath=siteName/applicationName
/p:MsDeployServiceUrl=http://10.1.1.4
/p:username=domain\tfsbuild2
/p:password=Abcd1234!
3.
<?xml version="1.0" encoding="utf-8"?> <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an attribute "name" that has a value of "MyDB". <connectionStrings> <add name="MyDB" //这里写发布后需要被替换的连接字符串的名字 connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" //connectionString为自动部署时要被设置的字符串 xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> //Match是匹配"name"来替换相应的value </connectionStrings> --> <system.web> <!-- In the example below, the "Replace" transform will replace the entire <customErrors> section of your web.config file. Note that because there is only one customErrors section under the <system.web> node, there is no need to use the "xdt:Locator" attribute. <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> --> </system.web> </configuration>
操作中还碰到个问题:同一个site/application路径,一个project可以自动部署,另一个则不行,提问在这儿。
总结:做到以上,就可以做自动化build和部署了!PS:如果没有特殊问题比如上边提到的问题。put down this just for reminding me of how to do some auto-build/deploy related stuff later.