简体   繁体   English

解决nuget包引用

[英]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). 我正在编写一个需要动态加载nuget软件包的应用程序(它使用Roslyn扫描文档,类型信息等)。

I have a situation where I want to load the following package (info derived from a csproj file): 我有一种情况想要加载以下程序包(从csproj文件派生的信息):

<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). 面临的挑战是,我的系统的nuget缓存没有针对netstandard2.0版本的Serilog.Sinks.Console 3.1.1的程序集/ DLL(我也不认为一个在线)。 All it has is one for netstandard1.3. 它所具有的只是netstandard1.3的一个。

Yet the app that I'm scanning (ie, the one with the requirement for Serilog.Sinks.Console 3.1.1 netstandard2.0) works perfectly fine. 但是我正在扫描的应用程序(即需要Serilog.Sinks.Console 3.1.1 netstandard2.0的应用程序)运行良好。 So the package requirement is being resolved, I presume, to the netstandard1.3 version...even though the project is netstandard2.0. 因此,我想将软件包要求解决为netstandard1.3版本...即使项目是netstandard2.0。

Questions: 问题:

  • what's the best place for documentation on how nuget packages are resolved at runtime? 关于在运行时如何解析nuget包的文档的最佳位置是什么? 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? 也许这是nuget本身的一部分? I studied the nuget github project but didn't see such a thing, but I don't pretend to be a nuget expert. 我研究了nuget github项目,但没有看到这样的事情,但是我不假装自己是nuget专家。

I would do something like: nuget update or nuget list and interact from C# etc with the console. 我会做类似的事情: nuget updatenuget list并从C#等与控制台进行交互。 That way you are sort of getting a library like behavior but not baking your own code that may break across nuget versions. 这样,您就可以得到类似行为的库,但不会烘焙可能会破坏nuget版本的代码。

NetStandard 1.3 is likely usable for Netstandard 2.0 as mentioned here (but not the other way around). NetStandard 1.3是Netstandard 2.0可能可用作提到这里 (而不是周围的其他方法)。

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版本控制将声明您要说的是Netstandard 2.0,而您使用的软件包可能会说它支持NetStandard 1.3+(隐式包括Netstandard 2.0)。 Nuget will select the highest one provided that suites your needs, in this case probably 1.3 as you indicated. 如果满足您的需求,Nuget将选择最高的一个,在这种情况下,可能是您指定的1.3。 Details are here on how nuget selects dependencies. 此处详细介绍了nuget如何选择依赖项。 I assume that this is the same way in how it determines runtime folders. 我认为这与确定运行时文件夹的方式相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM