MSbuild batch copy

69 Views Asked by At

Last time, i misinterpreted my situation, but you folks got me really quick and great solutions. hence coming back. I have a new situation. I have provide a snippet of my code. Not sure what is wrong.

I am trying to copy to multipleservers with same directory structure. Not sure what is wrong with it ...

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

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

<ItemGroup>
    <DestFldr Include="devsvr1;devsvr2"/>
    <DestToCopy Include="@(DestFldr)\$(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>

2

There are 2 best solutions below

1
On

%(DestCopy.FullPath) would represent the metadata for all items in the collection and doesn't convert to the property $(DestToCopy).

While posting a buggy script can show part of the picture, you also need to articulate what your goal is, what you're expecting to see, and what you're actually seeing.

0
On

I tired the below code and seem to be working, but not sure if this is an optimal solution ...

Can you experts please review ...

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