0

I am running into a situation. I am trying to use MSBuild batching to copy a folder (subdirectories as well as files) to mutilple dest folders. but when i run the below script, it dumps every content from the src (contents from sub directories too) in root target directory, whereas what i was looking was to get the exact same structure as in src in the target dirs.

<PropertyGroup>
        <Srcfldr>C:\helloworld\REService</Srcfldr>
    <DestFldr>C:\Projects\desire\Examples</DestFldr>
  </PropertyGroup>

  <ItemGroup>
    <SrcToCopy Include="$(Srcfldr)\*.*"/>
  </ItemGroup>

  <ItemGroup>
    <DestToCopy Include="$(DestFldr)/destfldr1"/>
    <DestToCopy Include="$(DestFldr)/destfldr2"/>
    <DestToCopy Include="$(DestFldr)/destfldr3"/>

  </ItemGroup>

   <Target Name="DeployBatching">
    <RemoveDir Directories="@(DestToCopy)"/>
    <MakeDir Directories="@(DestToCopy)"/>

    <Copy SourceFiles="@(SrcToCopy)" DestinationFolder="%(DestToCopy.FullPath)" />

Can you please tell me what am i doing wrong ...

SK

AnsibleUser
  • 65
  • 1
  • 8

3 Answers3

0

Vanilla copy task is better suited for copying files rather than directories, in any case to preserve structure you need to remap destination using %(RecursiveDir) and %(Filename)%(Extension) metadata. See second example on MSDN.

Edit:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <Srcfldr>C:\helloworld\REService</Srcfldr>
        <DestFldr>C:\Projects\desire\Examples</DestFldr>
    </PropertyGroup>

    <ItemGroup>
        <SrcToCopy Include="$(Srcfldr)\**\*"/>
    </ItemGroup>

    <ItemGroup>
        <DestToCopy Include="$(DestFldr)\destfldr1"/>
        <DestToCopy Include="$(DestFldr)\destfldr2"/>
        <DestToCopy Include="$(DestFldr)\destfldr3"/>
    </ItemGroup>

    <Target Name="DeployBatching" Outputs="%(DestToCopy.FullPath)">
        <PropertyGroup>
            <DestToCopy>%(DestToCopy.FullPath)</DestToCopy>
        </PropertyGroup>
        <RemoveDir Directories="@(DestToCopy)"/>
        <MakeDir Directories="@(DestToCopy)"/>
        <Copy
            SourceFiles="@(SrcToCopy)"
            DestinationFiles="@(SrcToCopy->'$(DestToCopy)\%(RecursiveDir)\%(Filename)%(Extension)')"
        />
    </Target>
</Project>
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
  • Doesn't look like it's working for me ... I tried the below code %(DestToCopy) – AnsibleUser Aug 11 '14 at 22:38
  • It's copying just the root files in the root directory, it is missing the directories and sub directories ... – AnsibleUser Aug 11 '14 at 22:41
  • @Satesh `$(Srcfldr)\**\*` here `**` means "at any level" and that's what `%(RecursiveDir)` is for. Read the example carefully. – Ilya Kozhevnikov Aug 11 '14 at 22:43
  • yes, copying to single destination folder works, but copying to multiple destination folder from single source of truth is problem for me still – AnsibleUser Aug 11 '14 at 23:02
  • somehow the comment was lost.. yes that worked as expected. Thanks @llYa – AnsibleUser Aug 18 '14 at 21:30
  • @llYa... had a quick question... incase i have multiple destination servers, with 1 source of truth to copy, but i need to append path to the destination server name, then i need to use array right ... i.e For Eg dev1 dev2 , but while copying i need to put into individual server dev1\fldr1\fldr2 and same to dev2\fldr1,fldr2. I should be able to do it in @(destsrv) right, but i am not able to append those folder paths – AnsibleUser Aug 26 '14 at 17:17
0

Doesn't look like it's working the way i wanted it to ... I tried the below code

<PropertyGroup>
        <Srcfldr>C:\helloworld\REService</Srcfldr>
    <DestFldr>C:\Projects\desire\Examples</DestFldr>
  </PropertyGroup>

  <ItemGroup>
    <SrcToCopy Include="$(Srcfldr)\*.*"/>
  </ItemGroup>

  <ItemGroup>
    <DestToCopy Include="$(DestFldr)/destfldr1"/>
    <DestToCopy Include="$(DestFldr)/destfldr2"/>
    <DestToCopy Include="$(DestFldr)/destfldr3"/>

  </ItemGroup>

<PropertyGroup>
        <DestToCopyvar>%(DestToCopy)</DestToCopyvar>
      </PropertyGroup>

        <Target Name="DeployBatching">

          <Copy SourceFiles="@(SrcToCopy)" DestinationFiles="@(SrcToCopy->'$(DestToCopyvar)\%(RecursiveDir)%(Filename)%(Extension)')" />

It's copying just the root files in the root directory, it is missing the directories and sub directories al together ...

AnsibleUser
  • 65
  • 1
  • 8
0

This seems to be working for me now ...

<PropertyGroup>
<Srcfldr>C:\Msbuild\exproj\Rebinaries</Srcfldr>
<copyfldr>c$\component1</copyfldr>
</PropertyGroup>

<ItemGroup>
<SrcToCopy Include="$(Srcfldr)\**\*"/>
</ItemGroup>

 <ItemGroup>
 <DestToCopy Include="\\devsvr1\$(copyfldr);\\devsvr2\$(copyfldr)"/>
 </ItemGroup>

 <Target Name="DeployBatching" Outputs="%(DestToCopy.FullPath)">
    <PropertyGroup>
        <DestToCopy>%(DestToCopy.FullPath)</DestToCopy>
    </PropertyGroup>
    <RemoveDir Directories="@(DestToCopy)"/>
    <MakeDir Directories="@(DestToCopy)"/>
    <Copy
        SourceFiles="@(SrcToCopy)"
        DestinationFiles="@(SrcToCopy->'$(DestToCopy)\%(RecursiveDir)\%(Filename)%(Extension)')"
    />
</Target>
AnsibleUser
  • 65
  • 1
  • 8