MSBuild同时构建Release和QA?

时间:2014-05-05 17:23:22

标签: visual-studio-2012 msbuild teamcity build-process

我在 TeamCity 中有一个有效的 msbuild 脚本,用于构建发布配置。我还需要它来构建“QA”配置并将其复制到QA文件夹。这可以在一个脚本中完成,还是我需要多个脚本?

<?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>AOP</SolutionName>
 <SolutionFile>AOP.sln</SolutionFile>
 <ProjectName>AOP.Web</ProjectName>
 <ProjectFile>AOP.Web\AOP.Web.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->'c:\devDeploy\AOP\$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
  </Target>
</Project>

1 个答案:

答案 0 :(得分:0)

如果它只是配置属性的值与QA不同,则可以在teamcity构建中添加另一个步骤,并使用QA配置值调用相同的MSBUild脚本。类似的东西:

msbuild.exe YourScript.proj /p:Configuration=DEBUG

或者,您可以尝试将脚本编辑为:

<PropertyGroup>
   <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
   <QAConfiguration Condition=" '$(Configuration)' == '' ">QAConfig</QAConfiguration>
   <SolutionName>AOP</SolutionName>
   <SolutionFile>AOP.sln</SolutionFile>
   <ProjectName>AOP.Web</ProjectName>
   <ProjectFile>AOP.Web\AOP.Web.csproj</ProjectFile>
</PropertyGroup>  

<Target Name="Build" DependsOnTargets="BuildPackage;CopyOutput;BuildQAPackage;CopyQAOutput" />
<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->'c:\devDeploy\AOP\$(Configuration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>

<Target Name="BuildQAPackage">
  <MSBuild Projects="$(SolutionFile)" ContinueOnError="false" Targets="Rebuild" Properties="Configuration=$(QAConfiguration)" />
  <MSBuild Projects="$(ProjectFile)" ContinueOnError="false" Targets="Package" Properties="Configuration=$(QAConfiguration)" />
</Target>

<Target Name="CopyQAOutput">
  <ItemGroup>
    <PackagedFiles Include="$(ProjectName)\obj\$(QAConfiguration)\Package\PackageTmp\**\*.*"/>
  </ItemGroup>
  <Copy SourceFiles="@(PackagedFiles)" DestinationFiles="@(PackagedFiles->'c:\devDeploy\AOP\$(QAConfiguration)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>