Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget package not installing dependencies for .NETCoreApp

I've created a nuget package which has 2 assemblies. One targeting .Net Framework 4.0 and another targeting .Net Standard 1.6.

This seems to work without any problems. However, the version targeting .NET Standard requires a couple of extra dependencies to function so I added these as dependencies in the nuspec file and rebuilt.

The dependencies show up as expected in the NuGet Package Manager but when I reference the package from a .Net Core or .Net Standard Application, it does not add references for the dependencies. The package seems to install fine, with no errors in the log.

This is the relevant part of my nuspec file:

<dependencies>
    <group targetFramework="netstandard1.3">
        <dependency id="System.Collections.Specialized" version="4.0.1.0" />
        <dependency id="System.Threading.Tasks.Parallel" version="4.3.0.0" />
    </group>
    <group targetFramework="netcoreapp1.0">
        <dependency id="System.Collections.Specialized" version="4.0.1.0" />
        <dependency id="System.Threading.Tasks.Parallel" version="4.3.0.0" />
    </group>
</dependencies> 

What am I missing here?

Edit:

A little more info:

I tried removing the grouping from the config above and just had the dependencies listed with no grouping, then I tried installing the package on a regular ASP.NET project.

When you install the package via Package Manager, a window pops up listing the packages that are being installed and in this case, it lists my package plus the dependencies. All good.

However, when I install the same package on a .NETCoreApp or .NETStandard project, only my package appears in the list.

Edit 2:

I've been discussing this with the very helpful people at NuGet support and discovered that if we use the same package, added to a .NET Core app in Visual Studio 2017 then it works fine, it's only in VS 2015 that the problem occurs.

They've asked me to raise an issue on github.

like image 583
Steve Avatar asked Oct 30 '22 08:10

Steve


2 Answers

In projects that use package reference to manage nuget dependencies, you do not have a project.json. Instead, all your references are available in a single place i.e. the project file. In dotnet core, or projects that use PackageReference, reference to only the immidiate dependencies are listed. So, if you add a reference to package A, which in turn depends on package B, B would not show up in your project file. This is a one of the biggest advantages of PackageRef where we don't clutter the project file with gazillion dependencies which the consumer probably doesn't care about. Install your nuget package to a project, navigate to the project_root/obj/project.assets.json and open this json, you'd see your package listed along with its dependencies. If you see your intended dependencies here, it validates that package is authored correctly.

like image 148
karann - MSFT Avatar answered Nov 15 '22 10:11

karann - MSFT


Maybe it causes by cache? try:

Clean cache at VS2017 > Tools > Options > NuGet Package Manager > General > Clear All NuGet Cache(s) (Actually in %USERPROFILE%\.nuget)

That works for me.

like image 45
John_J Avatar answered Nov 15 '22 09:11

John_J