Skip to content

CPS projects can't handle contentFiles from separate packages using the same file name #5048

Open
@davidmatson

Description

@davidmatson

ContentFilesCollision.zip

See the attached zip for a repro.

  1. Create a CPS style csproj.
  2. Reference multiple contentFiles packages that happen to use the same file name internally.
  3. Build (it succeeds)
  4. Close and re-open the solution.

Expected:
The project continues to load successfully.

Actual:
The project fails to load, with the error message:
"Duplicate linked item found in the project:..."

Note that, due to #5047, the bug does not appear immediately when the package references are added - it takes a solution reload to get the linked items to appear (and trigger this bug).

This bug does not occur in project.json-style NuGet, only in CPS-style NuGet, which now includes contentFiles as linked project items. This use of linked items seems to have a fundamental problem here - the project root is a shared namespace, and what file names each package happens to use internally shouldn't affect the ability to install both packages at once (it works with project.json), especially when these are not being copied to the output directory.

Suggested resolution:
Put code content files under a project node named after the package name (don't treat the project root as a shared area for all projects, as that can cause collisions when using multiple packages).

For example, link the items to paths something like this in the project tree:
.NuGetContent\ProjectA\NativeMethods.cs
.NuGetContent\ProjectB\NativeMethods.cs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions