我遇到了一个问题,即在 bin 中使用了较旧的 GAC 程序集而不是较新版本的程序集。

服务器:

Assembly version: ASP.NET MVC 3 RC 1 (3.0.11029.0)
Full name: System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Web.Mvc/v4.0_3.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed

开发机:
Assembly version: Unknown version (3.0.20105.0)
Full name: System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Mvc/v4.0_3.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed

较新的 RTM 版本 (3.0.20105.0) 位于应用程序的 bin 目录中。但是,该应用程序使用的是 GAC 中的一个,而不是本地 bin。我在 Windows 应用程序中的经验是本地 bin 部署的 DLL 始终优先,因为只有在与应用程序相同的目录中找不到 DLL 时才会检查 GAC。这种约定似乎不适用于 Web 应用程序。

如何强制它使用我较新版本的 bin 部署 DLL (3.0.20105.0)?

编辑:
我实际上确实尝试过像这样的绑定(bind)重定向:
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="3.0.11029.0" newVersion="3.0.20105.0" />

我在旧版本上尝试了几种变体,例如 0.0.0.0-4.0.0.0 。在我所有的尝试中,它通常要么加载旧版本,要么给我这个异常消息:
Could not load file or assembly 'System.Web.Mvc' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.

绑定(bind)日志没有任何错误,除了最后两行:
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

最佳答案

回答是 SO Dll in both the bin and the gac, which one gets used? 注意,您必须运行 strong name hijack 否则它将使用 GAC 版本。
我会重新标记这个,它不是 MVC 特定的。

关于asp.net - 对于 Web 应用程序,Bin 部署的 DLL 优先于 GAC 的 DLL 吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9593591/

10-12 22:28
查看更多