安装后程序集依赖项更改 [英] Assembly Dependencies Change After Installation

查看:33
本文介绍了安装后程序集依赖项更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .NET 应用程序,它的某些依赖版本似乎在调试和作为已安装的发布应用程序运行之间发生了变化.我将只关注 Castle.Core 程序集的详细信息,但同样的问题也发生在其他几个程序集上.我正在使用的 NuGet 包需要 Castle.Core 作为依赖项(我的问题的所有情况都与源自 NuGet 的程序集有关,以防万一).

I have a .NET application that seems to have some of its dependency versions change between debugging and running as an installed release app. I'll just focus on the Castle.Core assembly for my details, but the same issue occurs with a couple others as well. A NuGet package I'm using requires Castle.Core as a dependency (all cases of my issue are related to assemblies originating from NuGet, in case it matters).

在 Visual Studio 中,当我安装带有 Castle.Core 依赖项的 NuGet 包时,无论是在调试还是发布配置中,一切都运行良好.我可以看到 Castle.Core 项目参考引用了 3.3.0.0 版.但是,当我使用 InstallShield 打包由 Release 配置生成的所有内容并安装应用程序(所有程序集都位于同一程序目录中)时,我收到此运行时错误:

In Visual Studio, when I install the NuGet package with the Castle.Core dependency, everything runs just fine, both in Debug and Release configurations. I can see that the Castle.Core project reference is referencing version 3.3.0.0. However, when I package everything generated by the Release configuration using InstallShield and install the application (with all assemblies living in the same program dir), I get this runtime error:

无法加载文件或程序集Castle.Core,版本=3.2.0.0,Culture=neutral, PublicKeyToken=407dd0808d44fbdc' 或其中之一依赖关系.定位的程序集的清单定义没有匹配程序集引用.(来自 HRESULT 的异常:0x80131040)

Could not load file or assembly 'Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

NuGet 包将其对 Castle.Core 的依赖列为 (≥3.2.0.0 && < 4.0.0.0).3.2.0.0 和 3.3.0.0 都满足这些条件.

The NuGet package lists its dependency on Castle.Core as (≥3.2.0.0 && < 4.0.0.0). Both 3.2.0.0 and 3.3.0.0 satisfy those conditions.

如果我手动将 Castle.Core 降级到 3.2.0.0,我的项目参考显示它确实降级了.但是当我在 Visual Studio 中运行该项目时,我得到:

If I manually downgrade Castle.Core to 3.2.0.0, my project's reference shows that it has indeed downgraded. But when I run the project in Visual studio, I get:

无法加载文件或程序集Castle.Core,版本=3.3.0.0,Culture=neutral, PublicKeyToken=407dd0808d44fbdc' 或其中之一依赖关系.定位的程序集的清单定义没有匹配程序集引用.(来自 HRESULT 的异常:0x80131040)

Could not load file or assembly 'Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

有一个内部例外:

无法加载文件或程序集Castle.Core,版本=3.2.0.0,Culture=neutral, PublicKeyToken=407dd0808d44fbdc' 或其中之一依赖关系.定位的程序集的清单定义没有匹配程序集引用.(来自 HRESULT 的异常:0x80131040)

Could not load file or assembly 'Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

但是,如果我随后将其打包到安装程序中并将其作为已安装的应用程序启动,则它可以工作.

However, if I then package it into an installer and launch it as an installed application, it works.

对我来说,感觉就像将程序集打包到安装程序中的行为会导致依赖项版本发生变化.我无法想象会是这样,但我想不出更好的解释.

To me, it feels like the act of packaging the assemblies into an installer is causing the dependency versions to change. I can't imagine that to be the case, but I'm having trouble coming up with a better explanation.

谁能解释一下这里发生了什么以及我该如何解决?

Can anyone explain what's happening here and how I might fix it?

推荐答案

好的,想通了.首先,面掌

通过 NuGet 添加的程序集对 Castle.Core 3.2.0 具有特定的版本依赖性.但是,由于该程序集仍然可以与 Castle.Core 3.2.0-4.0.0 一起使用,因此向 App.config 添加了一个程序集绑定重定向,该重定向向程序集加载器指示需要该范围内版本的任何程序集都应尝试加载 Castle.Core 3.3.0,这是打包在我的应用安装程序中的版本.我没有意识到我没有在安装程序中包含配置文件,因此 Visual Studio 加载了配置文件而没有问题,而已安装的应用程序在应用程序目录中缺少该文件.

The assembly added via NuGet has a specific version dependency on Castle.Core 3.2.0. However, because that assembly can still work with Castle.Core 3.2.0-4.0.0, an assembly binding redirect got added to App.config that indicates to the assembly loader that any assemblies requiring a version in that range should try to load Castle.Core 3.3.0, which is the version that gets packaged in my app installer. I didn't realize that I had failed to include the config file in my installer, so the config got loaded in by Visual Studio without issue, while the installed app was missing that file in the app dir.

这篇关于安装后程序集依赖项更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆