문제

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