Resolving nuget package references

Mark Olbert

I am writing an app which needs to load nuget packages dynamically (it uses Roslyn to scan for documentation, type information, etc).

I have a situation where I want to load the following package (info derived from a csproj file):

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AssemblyName>J4JSoftware.Logging</AssemblyName>
    <RootNamespace>J4JSoftware.Logging</RootNamespace>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>

The challenge is that my system's nuget cache does not have an assembly/DLL for a netstandard2.0 version of Serilog.Sinks.Console 3.1.1 (I don't think one exists online, either). All it has is one for netstandard1.3.

Yet the app that I'm scanning (i.e., the one with the requirement for Serilog.Sinks.Console 3.1.1 netstandard2.0) works perfectly fine. So the package requirement is being resolved, I presume, to the netstandard1.3 version...even though the project is netstandard2.0.

Questions:

  • what's the best place for documentation on how nuget packages are resolved at runtime? Perhaps I could duplicate the resolving function in my scanning app.

  • better yet, is there a library that handles the resolution automagically? Perhaps something that's part of nuget itself? I studied the nuget github project but didn't see such a thing, but I don't pretend to be a nuget expert.

Dessus

I would do something like: nuget update or nuget list and interact from C# etc with the console. That way you are sort of getting a library like behavior but not baking your own code that may break across nuget versions.

NetStandard 1.3 is likely usable for Netstandard 2.0 as mentioned here (but not the other way around).

Nuget versioning would declare that you want say Netstandard 2.0 and the package you are using might say it supports NetStandard 1.3+ (which includes Netstandard 2.0 implicitly). Nuget will select the highest one provided that suites your needs, in this case probably 1.3 as you indicated. Details are here on how nuget selects dependencies. I assume that this is the same way in how it determines runtime folders.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to trace resolving process of nuget package references

Force project references to be included in netstandard nuget package

Nuget Package Installation is Not Adding References To Project

NuGet Package references copies dll local

SignalR references NuGet package(s) that are missing

Nuget package not adding Framework Assembly references

c# nuget package doesn't show up in references in VS

Install NuGet package without adding any references in Visual Studio

Xamarin.Android nuget package references System.Web

Nuget Package - Referenced Assemblies Are Not Being Included As Project References

How can I embed / reference .NET references in a NuGet package?

Xamarin Forms: This project references NuGet package(s) that are missing on this computer

Running dotnet watch run in docker container breaks Nuget package references

Versions not resolving for Nuget packages

NuGet: explicitly list package dependencies as package references in project so they can be uninstalled

Best practices on resolving references in MongoDB?

Resolving F# assembly references

Swift Package Manager not resolving

Resolving namespace resolution with NuGet and mono

Nuget Packages are there but missing References

Restoring Nuget References?

NuGet not updating project references

Nuget references not found

NuGet Install - Package 'EntityFramework.6.2.0' already exists in folder - csproj references another projects packages folder

Create NuGet package from .NET Core 3.1 class library project that references another class library project

Created a nuget package but when I reference it in my project I don't see it in the references

Unity - UWP: How to import dll/nuget-package/references to my project

ASP.NET Core 2.2 - How to retreive NuGet Package Dependencies from Assembly that a Project References

.Net Core Nuget Package Version mismatch: Two packages have references to different versions of the same dll