0

我面临的问题是我的目标“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>

4

2 回答 2

0

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

像这样的东西:

<Target Name="MyTarget">
    <PropertyGroup>
        <BuildFolder>... some path ... </BuildFolder>
    </PropertyGroup>
    <ItemGroup>   
        <SrcFiles Include="$(BuildFolder)_PublishedWebsites\**\*.*"/>   
    </ItemGroup>  
</Target>
于 2012-05-09T02:20:03.427 回答
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>
于 2012-05-10T01:29:06.470 回答