7

我有一个文本文件,其中包含要复制到临时目录的文件的一些位置

---- List.txt ----
Build\Java
Build\Classes

现在,我正在将此列表提取到一个项目中

<ReadLinesFromFile File="List.txt" >
    <Output TaskParameter="Lines"
            ItemName="DirectoryList" />
</ReadLinesFromFile>

现在,为了附加完整路径并添加一些排除项,我再次将其存储到另一个 ItemGroup 中:

<ItemGroup>
    <PackageList Include="$(BuildPath)\%(DirectoryList.Identity)\**\*.*"
                 Exclude="$(BuildPath)\%(DirectoryList.Identity)\**\*.pdb" />
</ItemGroup>

<Copy SourceFiles="@(PackageList)" 
      DestinationFiles="@(PackageList->'$(PackageTemp)\%(SourceDirectory)\%(DirInPackage)%(RecursiveDir)%(Filename)%(Extension)')" />

问题:

实际目录 -

C:\Work\Build\Java\Debug
C:\Work\Build\Java\Release
C:\Work\Build\Classes\*.class

O/p 中的内容

C:\temp\Debug
C:\temp\Release
C:\temp\*.class

如何让它也复制相应的“ Java”和“ Classes”文件夹?

4

2 回答 2

4

您在脚本中错过了一些片刻。首先,您需要从@(PackageList). 其次,在Copy设置任务时,DestinationFiles您应该明确指定子目录。

看一看。该票据可以根据您的需要完成工作。它包含通配符指定的所有子目录的内部结构。例如,Java\Debug\Component1\file.ext

    <Project DefaultTargets="CopyDirectories" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <BuildPath>.</BuildPath>
        <SourceDirectoryListFile>Directories.txt</SourceDirectoryListFile>
        <DestinationDirectory>temp</DestinationDirectory>
    </PropertyGroup>

    <Target Name="ReadDirectoryList">
        <ReadLinesFromFile File="$(SourceDirectoryListFile)" >
            <Output TaskParameter="Lines"
                    ItemName="DirectoryList" />
        </ReadLinesFromFile>
    </Target>

    <Target Name="CopyDirectories" DependsOnTargets="ReadDirectoryList"
            Outputs="%(DirectoryList.Identity)">
        <PropertyGroup>
            <ProcessingDirectory>%(DirectoryList.Identity)</ProcessingDirectory>
        </PropertyGroup>
        <ItemGroup>
            <PackageList Include="$(BuildPath)\$(ProcessingDirectory)\**\*.*"
                         Exclude="$(BuildPath)\$(ProcessingDirectory)\**\*.pdb" />
        </ItemGroup>
        <MakeDir Directories="$(ProcessingDirectory)" />
        <Copy SourceFiles="@(PackageList)"
              DestinationFiles="@(PackageList->'$(DestinationDirectory)\$(ProcessingDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
    </Target>
于 2012-05-29T11:17:29.580 回答
3

Arpit,您可以使用一种相反的解决方案:在 List.txt 中保留要从副本中排除的目录。基于,您可以使用 2 组目录创建您的 copyfileslist。

所以我的解决方案如下所示:

---- List.txt ---- dirs to be excluded --- 
Demos\AccessDatabase
Demos\ActiveDirectoryMsi
Demos\JavaToolsMsi
Demos\JavaToolsMsi\Data
Demos\LocalUserGroupsMsi
Demos\MSSQLDatabase
Demos\StringToolsMsi
Demos\SystemToolsMsi
Demos\TemplateFilesMsi
Demos\UserPrivilegesMsi
Demos\WindowsServiceMsi
Common
CustomActions
Framework
Tools
Version
WixExtensions

我的 msbuild.proj:

<Project DefaultTargets="run" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
    <Target Name="run">
        <PropertyGroup>
            <BuildPath>c:\tmp\msiext\msiext-1.3\trunk\src</BuildPath>
            <PackageTemp>c:\tmp\</PackageTemp>
        </PropertyGroup>        
        <ReadLinesFromFile File="List.txt" >
            <Output TaskParameter="Lines"
                ItemName="DirectoryList" />
        </ReadLinesFromFile>
        <Message Text="DirectoryList: @(DirectoryList)" />
        <ItemGroup>
            <PackageList Include="$(BuildPath)\%(DirectoryList.Identity)\**\*.*"
                Exclude="$(BuildPath)\%(DirectoryList.Identity)\**\*.sql" />
        </ItemGroup>
        <!--<Message Text="PackageList: @(PackageList)" />-->

        <Message Text="----------------------------------------------------------------------------" />
        <CreateItem Include="$(BuildPath)\**\*.*" Exclude="@(PackageList)">
            <Output TaskParameter="Include" ItemName="NeededFiles"/>
        </CreateItem>

        <Message Text="NeededFiles: @(NeededFiles)" />
        <Message Text="----------------------------------------------------------------------------" />
        <Copy SourceFiles="@(NeededFiles)" DestinationFiles="@(NeededFiles->'$(PackageTemp)\%(RecursiveDir)\%(Filename)%(Extension)')" />
    </Target>
</Project>
于 2012-05-24T12:11:02.993 回答