组装依赖关系在安装后更改 [英] Assembly Dependencies Change After Installation

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

问题描述

我有一个.NET应用程序似乎有一些依赖版本在调试和运行之间作为安装的版本应用程序发生变化。我将仅关注Castle.Core大会的细节,但同样的问题也与其他几个人一起发生。我正在使用的NuGet包需要Castle.Core作为依赖(所有与我的问题有关的事件都与源自NuGet的程序集相关,以备事项)。



Visual Studio,当我安装了具有Castle.Core依赖性的NuGet软件包时,Debug和Release配置中的所有内容都运行正常。我可以看到Castle.Core项目引用引用了3.3.0.0版本。但是,当我使用InstallShield打包发布配置生成的所有内容,并安装应用程序(所有程序集都在同一程序目录中)时,我收到此运行时错误:


无法加载文件或程序集Castle.Core,Version = 3.2.0.0,
Culture = neutral,PublicKeyToken = 407dd0808d44fbdc或其
依赖关系之一。找到的程序集的清单定义不是
匹配程序集引用。 (HRESULT的异常:0x80131040)


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



如果我将Castle.Core手动降级为3.2.0.0,我的项目参考表明它已经降级了。但是当我在Visual studio中运行该项目时,我得到:


无法加载文件或程序集CastleCore,Version = 3.3。 0.0,
Culture = neutral,PublicKeyToken = 407dd0808d44fbdc'或其
依赖关系之一。找到的程序集的清单定义不是
匹配程序集引用。 (来自HRESULT的异常:0x80131040)


其中有一个例外:


无法加载文件或程序集Castle.Core,Version = 3.2.0.0,
Culture = neutral,PublicKeyToken = 407dd0808d44fbdc或其
依赖关系之一。找到的程序集的清单定义不是
匹配程序集引用。 (来自HRESULT的异常:0x80131040)


但是,如果我将它打包成安装程序并将其作为已安装的应用程序启动,



对我来说,感觉像将程序集打包成一个安装程序的行为正在导致依赖关系版本的改变。我不能想像是这样,但是我无法想出更好的解释。



任何人都可以解释这里发生了什么,以及我如何解决

解决方案

好的,想出来了首先, facepalm



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


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).

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:

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)

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.

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:

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)

with an inner exception of:

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?

解决方案

Ok, figured it out. First, facepalm

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天全站免登陆