我大多数情况下都不需要自定义msbuild脚本。以下是相关的TeamCity构建配置设置:
工件路径:%system.teamcity.build.workingDir%\ MyProject \ obj \ Debug \ Package \ PackageTmp
运行程序类型:MSBuild(用于MSBuild文件的运行程序)
生成文件路径:MyProject \ MyProject.csproj
工作目录:与结帐目录相同
MSBuild版本:Microsoft .NET Framework 4.0
MSBuild工具版本:4.0
运行平台:x86
目标:包装
MSBuild.exe的命令行参数:/ p:Configuration = Debug
这将进行编译,打包(通过web.config转换),并将输出保存为工件。唯一缺少的是将输出复制到指定的位置,但是可以在另一个带有工件依赖项或使用msbuild脚本的TeamCity构建配置中完成。
更新资料
这是一个msbuild脚本,它将编译,打包(通过web.config转换)并将输出复制到我的登台服务器
<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<SolutionName>MySolution</SolutionName>
<SolutionFile>$(SolutionName).sln</SolutionFile>
<ProjectName>MyProject</ProjectName>
<ProjectFile>$(ProjectName)\$(ProjectName).csproj</ProjectFile>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="BuildPackage;CopyOutput" />
<Target Name="BuildPackage">
<MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(Configuration)" />
<MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(Configuration)" />
</Target>
<Target Name="CopyOutput">
<ItemGroup>
<PackagedFiles Include="$(ProjectName)\obj\$(Configuration)\Package\PackageTmp\**\*.*"/>
</ItemGroup>
<Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'\\build02\wwwroot\$(ProjectName)\$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
您还可以从PropertyGroup标记中删除SolutionName和ProjectName属性,并将它们传递给msbuild。
msbuild build.xml /p:Configuration=Deploy;SolutionName=MySolution;ProjectName=MyProject
更新2
由于此问题仍然引起大量访问,因此我认为有必要使用当前使用Web Deploy的脚本(也称为MSDeploy)更新我的答案。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<ProjectFile Condition=" '$(ProjectFile)' == '' ">$(ProjectName)\$(ProjectName).csproj</ProjectFile>
<DeployServiceUrl Condition=" '$(DeployServiceUrl)' == '' ">http://staging-server/MSDeployAgentService</DeployServiceUrl>
</PropertyGroup>
<Target Name="VerifyProperties">
<!-- Verify that we have values for all required properties -->
<Error Condition=" '$(ProjectName)' == '' " Text="ProjectName is required." />
</Target>
<Target Name="Build" DependsOnTargets="VerifyProperties">
<!-- Deploy using windows authentication -->
<MSBuild Projects="$(ProjectFile)"
Properties="Configuration=$(Configuration);
MvcBuildViews=False;
DeployOnBuild=true;
DeployTarget=MSDeployPublish;
CreatePackageOnPublish=True;
AllowUntrustedCertificate=True;
MSDeployPublishMethod=RemoteAgent;
MsDeployServiceUrl=$(DeployServiceUrl);
SkipExtraFilesOnServer=True;
UserName=;
Password=;"
ContinueOnError="false" />
</Target>
</Project>
在TeamCity的,我有一个名为参数env.Configuration
,env.ProjectName
和env.DeployServiceUrl
。MSBuild运行程序具有构建文件路径,并且参数会自动传递(您不必在命令行参数中指定它们)。
您也可以从命令行运行它:
msbuild build.xml /p:Configuration=Staging;ProjectName=MyProject;DeployServiceUrl=http://staging-server/MSDeployAgentService