MSBuild复制任务问题

时间:2012-05-09 01:48:04

标签: .net msbuild tfs2010

我遇到的问题是我的目标'CopyBuildFiles'没有复制,因为我认为它无法找到构建文件夹。构建文件夹在属性$(BuildFolder)中定义,此文件夹名称是基于date.time创建的,并且是在“CopyBuildFiles”之前运行的先前目标之一中创建的。

如果我对@(SrcFiles)的路径进行硬编码而不是从$(BuildFolder)派生它,那就可以了。

任何想法,这里发生了什么以及如何解决这个问题?

非常感谢。

<PropertyGroup>

    <year>$([System.DateTime]::Now.ToString("yy"))</year>
    <month>$([System.DateTime]::Now.ToString("MM"))</month>
    <day>$([System.DateTime]::Now.ToString("dd"))</day>
    <time>$([System.DateTime]::Now.ToString("HHmm"))</time>
    <AssemblyFileVersionAttribute>[$(year).$(month).$(day).$(time))]      </AssemblyFileVersionAttribute>
    <BuildFolder>c:\website.builds\$(AssemblyFileVersionAttribute)\</BuildFolder>
    <IISFolder>c:\website.publish\</IISFolder>        
    <LogDirectory>C:\website.builds.logs</LogDirectory>
    <LogFile>C:\website.builds.logs\Buildlog_$(AssemblyFileVersionAttribute).txt</LogFile>

</PropertyGroup>


<Target Name="PreBuild">
    <MakeDir Directories="$(LogDirectory)" />       
    <RemoveDir Directories="$(IISFolder)"></RemoveDir>        
    <MakeDir Directories="$(BuildFolder)" />
    <MakeDir Directories="$(IISFolder)" />        
</Target>

<Target Name="Compile">
    <MSBuild Projects="$(MSBuildStartupDirectory)\websitev2.sln"  Properties="OutDir=$(BuildFolder)\" />        
</Target>

<ItemGroup>
    <SrcFiles Include="$(BuildFolder)_PublishedWebsites\**\*.*"/>
</ItemGroup>

<Target Name="CopyBuildFiles"
          Inputs="@(SrcFiles)"
          Outputs=
      "@(SrcFiles->'$(IISFolder)%(RecursiveDir)%(Filename)%(Extension)')">
    <Copy SourceFiles="@(SrcFiles)"
          DestinationFiles="@(SrcFiles->'$(IISFolder)%(RecursiveDir)%(Filename)%(Extension)')"
      />      
</Target>

<Target Name="Deploy">
    <CallTarget Targets="PreBuild" />
    <CallTarget Targets="Compile" />
    <CallTarget Targets="CopyBuildFiles" />
</Target>

2 个答案:

答案 0 :(得分:0)

由于您的一个目标定义了$(BuildFolder)属性,因此需要在同一目标中定义@(SrcFiles)项目组,或者在定义$(BuildFolder)之后执行的某个其他目标中定义。

这样的事情:

<Target Name="MyTarget">
    <PropertyGroup>
        <BuildFolder>... some path ... </BuildFolder>
    </PropertyGroup>
    <ItemGroup>   
        <SrcFiles Include="$(BuildFolder)_PublishedWebsites\**\*.*"/>   
    </ItemGroup>  
</Target>

答案 1 :(得分:0)

Replaced ItemGroup with **CreateItem**. This makes the copy work. 
**CreateItem** works without parameters. The folder name did not get passed through a parameter for some reason??!?

<Target Name="BuildInit">
    <CreateItem Include="$(BuildFolder)_PublishedWebsites\**\*.*">
      <Output TaskParameter="Include" ItemName="YourFilesToCopy" />
    </CreateItem>

    <Copy SourceFiles="@(YourFilesToCopy)"
                    DestinationFiles="@(YourFilesToCopy->'$(IISFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
  </Target>