1

I have created a build file using MSBuild which builds solution and keep all the data into a folder. Now i want to copy all the data to a remote machine accessed via shared folder.

 <PropertyGroup>
    <PublishDir>\\remoteMachineName\QA</PublishDir>
    <ServiceLocationQA>remoteMachineName\QA</ServiceLocationQA>
    <MachineName>remoteMachineName</MachineName>
  </PropertyGroup>

<ItemGroup>
       <Source Include=".\buildartifacts\**\*.*"/>
    <ServiceFilesToDeploy Include=".\buildartifacts\**\*.*" />
 </ItemGroup>

<Copy SourceFiles=".\buildartifacts\**\*.*"
       DestinationFiles="@(ServiceFilesToDeploy->'$(PublishDir)\%(RecursiveDir)%(Filename)%(Extension)')"
          ContinueOnError="false" />

After executing the the build script, i get following error:

"DestinationFiles" refers to 48 item(s), and "SourceFiles" refers to 1 item(s). They must have the same number of items."

I just want to copy files kept on local machine onto a shared location on a remote machine using MSBuild. Please help

SharpCoder
  • 18,279
  • 43
  • 153
  • 249

2 Answers2

2

You need to iterate the files:

    <Copy SourceFiles="%(ServiceFilesToDeploy.Identity)"
       DestinationFiles="@(ServiceFilesToDeploy->'$(PublishDir)\%(RecursiveDir)%(Filename)%(Extension)')"
          ContinueOnError="false" />

That way the copy task will be called for each file in ServiceFilesToDeploy.

MikeR
  • 3,045
  • 25
  • 32
  • Thank you for quick reply. Can you please explain what this code is doing. – SharpCoder Jun 04 '13 at 08:32
  • 1
    The difference is, that your code will use a list of files as input, while doing it my way, will iterate the list and call the target for each element. Check http://stackoverflow.com/questions/16540562/msbuild-copy-entire-directory-while-using-metadata-in-path-names there I explained the batching in MSBuild a bit. – MikeR Jun 04 '13 at 09:52
0

You dont even need to do batching as the copy task understands itemgroups:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Test">
    <PropertyGroup>
      <PublishDir>\\remotemachine\test</PublishDir>
      <BuildArtifacts>.\buildartifacts</BuildArtifacts>
    </PropertyGroup>

    <ItemGroup>
      <Source Include="$(BuildArtifacts)\**\*.*"/>
    </ItemGroup>

    <Copy SourceFiles="@(Source)"
           DestinationFolder="$(PublishDir)\%(RecursiveDir)"/>
  </Target>
</Project>
James Woolfenden
  • 6,498
  • 33
  • 53