Skip to content

Copy task should error if copying multiple sources to the same destination path #989

@brthor

Description

@brthor

A project with multiple items with CopyToOutputDirectory and conflicting assigned TargetPaths will cause the last file to be copied to the TargetPath.

I'm not certain this is a bug, but the behavior seems non-intuitive. It seems like multiple files trying to output to the same TargetPath should cause an error.

An example:

<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
    <EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
    <Content Include="Program.cs;project.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <Link>otherfilename.json</Link>
    </Content>
  </ItemGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

onlyproject.json will be copied to otherfilename.json and no error is thrown.

cc @rainersigwald @cdmihai @eerhardt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: TasksIssues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll.triaged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions