user4266661
user4266661

Reputation:

Resolving nuget package references

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:

Upvotes: 0

Views: 140

Answers (1)

Dessus
Dessus

Reputation: 2177

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.

Upvotes: 0

Related Questions