2012-05-09 147 views
0

我面對的問題是我的目標'CopyBuildFiles'不復制,因爲我認爲它無法找到生成文件夾。 build文件夾是在$(BuildFolder)屬性中定義的,該文件夾名稱是基於date.time創建的,並且是在'CopyBuildFiles'之前運行的之前的一個目標中創建的。MSBuild複製任務問題

如果我硬編碼@(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> 

+0

如果運行與命令行的MSBuild「/冗長:診斷」標誌,什麼是輸出說呢? – SuperJumbo

回答

0

由於你的目標之一定義了$(BuildFolder)屬性時,@(SrcFiles)項目組需要在同一目標也定義,或在其他一些定義$(BuildFolder)後執行的目標。

事情是這樣的:

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

好的,我創建了 c:\ website.builds \ $(AssemblyFileVersionAttribute)並且在PreBuild目標之後調用這個,仍然沒有運氣。 –

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>