Search code examples
msbuildmsbuild-taskmsbuild-4.0msbuildextensionpack

Copy files kept on local machine onto a shared location on a remote machine using MSBuild


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


Solution

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