Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidmatson opened this issue Apr 17, 2017 · 4 comments
Labels
Area:ContentFiles PackageReference contentFiles folder Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Style:PackageReference
Milestone

Comments

@davidmatson
Copy link

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

@davidmatson
Copy link
Author

This issue is currently blocking us from switching from project.json to CPS-style (PackageReference) csproj. We use .Sources (contentFiles with cs code) fairly extensively, and in practice most projects fail to load today if we try to convert, due to this bug.

@emgarten
Copy link
Member

Ideally there would be an option to have restore de-duplicate these or place them under a folder as you suggested.

Until that is added you can update the compile items in your project to workaround this. This builds on your previous fix.

Place items under the package id:

<ItemGroup>
    <Compile Update="@(Compile)">
	  <Link Condition=" '%(NuGetPackageId)' != '' ">%(NuGetPackageId)\%(Link)</Link>
    </Compile>
</ItemGroup>

Remove the link completely:

<ItemGroup>
    <Compile Update="@(Compile)">
	  <Link Condition=" '%(NuGetPackageId)' != '' "></Link>
    </Compile>
</ItemGroup>

@davidmatson
Copy link
Author

Yes, that's a good workaround - thanks!

@mishra14 mishra14 added Functionality:Restore Area:ContentFiles PackageReference contentFiles folder Triage:Investigate Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. labels Oct 17, 2017
@mishra14 mishra14 added this to the Backlog milestone Oct 17, 2017
@mishra14
Copy link
Contributor

@jainaashish @nkolev92 who are working on improving NuGet support for PackageReference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ContentFiles PackageReference contentFiles folder Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Style:PackageReference
Projects
None yet
Development

No branches or pull requests

6 participants