我如何解决Nuget DLL地狱-无论我做什么VS坚持认为dll版本与软件包中的版本不同

旧编码器

在更新Nuget之后,我已经为DLL的地狱而奋斗了一个多星期。我设法通过手动编辑解决方案,项目和包文件解决了大多数问题。但是,无论我做什么VS都坚持认为dll版本与Nuget安装的版本不同。有问题的库是MailKit,在更新之前可以正常使用。现在,已安装的版本是2.4.1,但是尽管显示了正确的位置,属性网格仍坚持认为版本2.4.0是:

属性网格显示所显示的版本不正确

我尝试了以下所有方法,但都没有成功:

  • 更新包-重新安装
  • 手动删除Nuget缓存
  • 手动删除计算机上2.4.0 dll的每个单个副本
  • 在整个代码库中搜索对2.4.0的任何引用,然后手动编辑代码以删除引用或重新编号为正确的版本
  • 从命令行删除Nuget缓存
  • 我能找到的所有其他建议都可以作为StackOverflow上的解决方案

无论我做什么,它仍然显示错误的版本,因此,当应用程序运行时,由于正确的版本是本地复制的,因此会引发异常。

谁能建议我如何解决这个问题?

编辑:

软件包配置:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="BouncyCastle" version="1.8.5" targetFramework="net452" />
  <package id="JetBrains.Annotations" version="2019.1.3" targetFramework="net452" />
  <package id="MailKit" version="2.4.1" targetFramework="net452" />
  <package id="MimeKit" version="2.4.1" targetFramework="net452" />
</packages>

项目文件(仅引用MailKit和MimeKit,其余部分均删除为不必要,让我知道是否需要更多内容):

<Reference Include="MailKit, Version=2.4.1, Culture=neutral, PublicKeyToken=4e064fe7c44a8f1b, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\MailKit.2.4.1\lib\net45\MailKit.dll</HintPath>
</Reference>
<Reference Include="MethodExtensions, Version=1.0.4469.11621, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\Libraries\MethodExtensions\bin\Debug\MethodExtensions.dll</HintPath>
</Reference>
<Reference Include="MimeKit, Version=2.4.1, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\MimeKit.2.4.1\lib\net45\MimeKit.dll</HintPath>
</Reference>

进一步编辑:

为了澄清起见,该软件包安装的dll版本显然是2.4.1:

引用的DLL的属性

Here is the runtime error message confirming that it is looking for 2.4.0 which is no longer on the computer following the Nuget update:

运行时错误消息

The Solution

The answer from @zivkan pointed me in the right direction. Firstly I was looking for entirely the wrong thing, assuming that the version in the Property Grid was incorrect when in fact it was perfectly fine. The reference is located in a plugin module which itself compiles to a library, which means that when compiling the MailKit dll not only has to be copied local but then copied to the main application folder using a post build event command line. It turns out that there was an error in the post build event code so that MailKit was not copied and MimeKit was copied twice. Not taking the blame for that one, but I do take the blame for not recognising the problem!

Thanks, @zirkan, for your help and explanation which finally got me to the resolution...

zivkan

when the app runs it throws an exception since the correct version is copied local.

Do you mean incorrect? I don't see why an exception will be thrown if the correct version is copied. In any case, it would have been more helpful if you showed us the actual error you got. I'm going to spend the rest of this answer explaining why everything else is working as designed, meaning you haven't given us enough information to understand your problem, so it's hard to suggest a good solution.

Anyway, a NuGet package is just a zip file (renamed .nupkg) that contains some files, usually some .NET assemblies. So, giving away the fundemental issue, what happens if the different assemblies in the package have different versions? The answer is nothing because assembly version and package version are independent. Often they're similar, or (almost) exactly the same, but since they're independent there's no reason they can't be different.

An assembly also has multiple versions. Firstly, if you find the .dll in Windows explorer, right click, select properties and go to the details tab, you'll see that all (or most) dlls have a product version and a file version. This is not specific to .NET, all windows executables have this metadata. If you use ILSpy or something similar to inspect the .NET assembly, you'll see there are AssemblyFileVersion, AssemblyInformationalVersion and AssemblyVersion attributes. So all together there are at least 5 different version metadata, and they're all independent and therefore can be different. That's before we consider NuGet package version is a 6th independent version number.

Now, the assembly in the properties window doesn't know anything about NuGet. It's showing you the path to the file, and since NuGet extracts packages to a path that includes the package version, we can see it in the path. But the version shows in the properties window is the assembly version. So, in this case the MailKit v2.4.1 package contains MailKit.dll with assembly version 2.4.0.0. Visual Studio's property window is showing you the correct information, there is no problem.

我的回答已经足够长了,所以我不会赘述很多,但是软件包作者可能会选择在其软件包的多个版本中使用相同的程序集版本,以最大程度地减少需要绑定重定向的次数。但是,这仅在不同产品版本兼容时才有效。当它们不兼容并且两个不同的程序集都依赖于相同的程序集版本的依赖关系时,就不可能同时加载两个不同的版本以解决此问题(是的,当同一个程序集具有不同的程序集版本时,则可以同时加载两者,这需要额外的精力)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

选择 nuget 包会导致依赖 dll 地狱吗?

DLL地狱与SQLite

了解DLL的地狱

升级到ASP.NET MVC 5和Web API 2后如何解析nuget DLL地狱

DLL地狱-如果缺少MySql.Data.dll版本6.9.3.0或6.8.3.0,我的应用程序将引发错误

Nuget DLL地狱:无法加载文件或程序集System.Runtime

为什么我坚持使用某个版本的软件包?

什么是 Nuget UNC 路径,我该如何解决?

如何解决dotnet核心中的nuget依赖地狱?

如何修复引用特定NuGet软件包提供的dll版本的托管C ++程序集(VS2017)

为什么我应该将NuGet软件包dll添加到源代码管理中?

我如何在NuGet v3 API中具有本地软件包的程序集(dll)?

我该如何解决“软件包'ddply'不可用(对于R版本3.6.2)”

如何解决找不到DLL的问题

无论我做什么,VSCode Python版本在集成终端中默认为2.7

我该如何解决?

我该如何解决

如何解决这个Maven的依赖地狱

我该如何解决?“ mscorlib.dll中发生了'System.IO.IOException'类型的首次机会异常”

Vue安装由于软件包版本不匹配而失败-如何解决?

如何解决Composer的“稳定版本不可用的软件包”错误?

我该如何解决我的病情

我有什么版本的Cordova,该如何解决?

发布后安装的nuget软件包取决于较旧版本的System.Web.Mvc.dll

.Net Core Nuget程序包版本不匹配:两个程序包引用了相同dll的不同版本

什么是IndexOutOfBoundsException?我该如何解决?

什么是NullPointerException,我该如何解决?

什么是NullReferenceException,我该如何解决?

什么是错误?我该如何解决?