سؤال

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

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top