简体   繁体   English

NuGet包版本不匹配参考版本

[英]NuGet Package version not matching reference version

I have been debugging an issue with my program and I find that the version of a couple of my NuGet packages do not match the version displayed in Reference Properties. 我一直在调试我的程序的问题,我发现我的几个NuGet包的版本与Reference Properties中显示的版本不匹配。 For instance, looking at my installed NuGet packages I have the following: 例如,查看我安装的NuGet包,我有以下内容:

在此输入图像描述

When I select log4net in the References group (under Solution Explorer) I see this: 当我在References组中选择log4net时(在解决方案资源管理器下),我看到:

在此输入图像描述

NuGet reports that the installed version is 2.0.5 but the Reference reports a version of 1.2.15. NuGet报告已安装的版本为2.0.5,但Reference报告版本为1.2.15。

Can someone explain why this is and if this is an issue? 有人可以解释为什么会这样,如果这是一个问题? I have the same issue with Newtonsoft.Json where NuGet shows a version of 8.0.3 but References shows a version of 8.0.0 我和Newtonsoft.Json有同样的问题,其中NuGet显示的是8.0.3的版本但是References显示的是8.0.0的版本

The trick is that you are comparing different things. 诀窍是你要比较不同的东西。

Nuget shows you available packages with their package version numbers . Nuget会显示包含其包版本号的可用包。 This is what the package owner has stated in package version field in nuget spec file . 这是包所有者在nuget spec文件的version字段中声明的内容 This version has no meaning or impact after nuget has done its job of fetching those external files to your project. 在nuget完成将这些外部文件提取到项目之后,此版本没有任何意义或影响。 Nor has it any direct relation to what's exactly contained within the package. 它与包装中的确切含义没有任何直接关系。

The reference properties on the other hand looks at a dll and does not care from which package it came from. 另一方面,引用属性查看dll,而不关心它来自哪个包。 The version shown is the version number embedded in DLL during compilation using the AssemblyVersionAttribute attribute in code. 显示的版本是在编译期间使用代码中的AssemblyVersionAttribute属性嵌入DLL中的版本号 This is the version actually used during runtime to find and load the referenced logic. 这是在运行时期间实际用于查找和加载引用逻辑的版本。

Usually it would make sense if a package version and dll versions match, but there are no hard rules to enforce this. 通常,如果包版本和dll版本匹配会有意义,但没有硬性规则来强制执行此操作。 It would get tricky even if it did, as a package could contain many dlls and other files, each versioned differently. 它会变得棘手,即使它确实如此,因为一个包可能包含许多dll和其他文件,每个文件版本不同。

Regarding this specific case, I have no information why the owners have made that difference nor whether it in accordance with their versioning logic. 关于这个具体案例,我没有任何信息,为什么业主已经做出了这种差异,也没有根据他们的版本逻辑。 If this is not documented then you could send them a message and ask about its meaning. 如果没有记录,那么您可以向他们发送消息并询问其含义。

The good thing is, a little confusion aside, if the dll does what you expect it to do and passes the QA then the version number difference in package does not matter in practice. 好处是,除了一点混乱之外,如果dll做了你期望它做的事情并通过质量保证,那么包中的版本号差异在实践中无关紧要。

Edit: Note that version number difference in just the 3rd number is common for libraries utilizing semantic versioning practice where the third component bump represents a non-breaking bugfix release. 编辑:请注意,只有第3个数字的版本号差异对于使用语义版本控制实践的库来说很常见,其中第三个组件凹凸表示不间断的错误修复版本。 Keeping the same AssemblyVersion (ex: "8.0.0" for Newtonsoft.Json) allows for in-place upgrade without recompiling all assemblies referencing the previous versions with same major-minor (8.0.0, 8.0.1, 8.0.2). 保持相同的AssemblyVersion (例如:Newtonsoft.Json的“8.0.0”)允许就地升级,而无需重新编译引用具有相同major-minor(8.0.0,8.0.1,8.0.2)的先前版本的所有程序集。

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

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