MS Build copy the list of directories stored in the item

I have a text file that contains some file locations that I want to copy to the temp directory

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

Now I am extracting this list into an element

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

Now, to add the full path and add some exceptions, I again store it in another ItemGroup:

 <ItemGroup> <PackageList Include="$(BuildPath)\%(DirectoryList.Identity)\**\*.*" Exclude="$(BuildPath)\%(DirectoryList.Identity)\**\*.pdb" /> </ItemGroup> <Copy SourceFiles="@(PackageList)" DestinationFiles="@(PackageList->'$(PackageTemp)\%(SourceDirectory)\%(DirInPackage)%(RecursiveDir)%(Filename)%(Extension)')" /> 

QUESTION:

Actual Dir -

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

Content in O / p

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

How to copy the corresponding folder " Java " and " Classes "?

+6
source share
2 answers

Arpit, you can use some inverse solution: save the files you want to exclude from the copy in List.txt. Based on this , you can create your copy list with 2 sets of dirs.

So my solution looks like this:

 ---- 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 

My 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> 
+3
source

You missed just a few seconds in your script. First, you need to create a directory from @(PackageList) . Secondly, in the Copy Task when installing DestinationFiles you must explicitly specify a subdirectory.

Take a look. This script does this work as needed. And it contains the internal structure of all of your subdirectories specified by a wildcard. For example, 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> 
+3
source

Source: https://habr.com/ru/post/916327/


All Articles