使用MsBuild进行每日构建

时间:2011-08-03 14:07:10

标签: msbuild

我想要做的是将OutputPath中的所有文件和子文件夹复制到每日文件夹。例如,我有一个名为Clock的项目,我有msbuild脚本:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ProjectPath>C:\Clock</ProjectSolutionName>
    <ProjectSolutionName>Clock</ProjectSolutionName>
  </PropertyGroup>

  <Target Name="ReleaseBuild">
    <Message Text="Building $(ProjectSolutionName) Release Build" />
    <MSBuild Projects="$(ProjectPath)\$(ProjectSolutionName).sln" Targets="Clean" Properties="Configuration=Release" />
    <MSBuild Projects="$(ProjectPath)\$(ProjectSolutionName).sln" Targets="Build" Properties="Configuration=Release" />
    <Message Text="$(ProjectSolutionName) Release Build Complete!" />
  </Target>
</Project>

现在,当我运行脚本时,它会编译解决方案,文件将存储到Release文件夹中。如何将Release文件夹中的所有文件和子文件夹复制到名为日期的文件夹,例如今天:C:\Clock_Builds\20110803

1 个答案:

答案 0 :(得分:2)

这应该做你要求的大部分内容(它的msbuild 4):

<Project DefaultTargets="DateCopy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="DateCopy">
   <ItemGroup>
      <Release Include="d:\Build\**\**"/>
   </ItemGroup>

   <PropertyGroup>
      <StringDate>$([System.DateTime]::Now.ToString('yyyyMMdd'))</StringDate>
   </PropertyGroup>

   <MakeDir Directories="D:\Release\$(StringDate)"/>

   <Message Text="$(StringDate)" Importance="High"/>
   <Copy SourceFiles="@(Release)"
         DestinationFolder="D:\Release\$(StringDate)\%(RecursiveDir)"/>
</Target>
</Project>

希望有所帮助