NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Dll's packed as contentFiles can be referenced in a consumer project #7551

Open noahmarcus opened 5 years ago

noahmarcus commented 5 years ago

Details about Problem

NuGet product used: dotnet.exe NuGet version: 4.5.1.4879 dotnet.exe --version: 2.1.402 OS version: win10 v1809 (17763.134)

Dll's packed as content with build action content or none can be referenced by consumer projects. My use case is packing a self-contained health checking application for a process which runs on Docker. I can't deliver the application as a NuGet package, as the application which is including it will reference the dlls from the self contained application and fails to build as they are incompatible.

Repro Steps

  1. Pack netcore2.1 system dll's as contentFiles (build action none or content). I've been using System.Core.dll

  2. Include the package in a project. targeting net47.

  3. The packaged dlls will be referenced by the project if it would have a reference to the net47 version of the dll.

OR

  1. Download and build attached Consumer.csproj.

If you take a look at a binlog, the System.Core.dll from the package is being chosen as a reference. The uploaded System.Core.dll is for netcore2.1

Sample Project

NugetRepro.zip

There are two projects here - Package.csproj, from which I created a package using dotnet pack, and Consumer.csproj, which I build using dotnet build. If you generate a binlog, the packed dll is being used as a reference.

toconnorcdx commented 5 years ago

I am encountering this same issue:

Unsurprisingly, the issue only arose after switching the netcore1.1 app to self-contained app .

For the interim, I have to

NuGet's contentFiles should not be a legitimate path for referencing assemblies