简体   繁体   English

bin和gac中的dll,哪一个被使用?

[英]Dll in both the bin and the gac, which one gets used?

We have a web application that's deployed to many websites with only frontend changes, the shared backend portion has it's DLL in the GAC so we only have to update that one dll and all the sites get the update. 我们有一个部署到许多网站的Web应用程序只有前端更改,共享后端部分在GAC中有它的DLL,因此我们只需要更新那个dll并且所有站点都获得更新。

Is there a way to override the GAC with a DLL in the /bin folder to test out new features before they get released? 有没有办法在/ bin文件夹中使用DLL覆盖GAC以在新功能发布之前测试它们?

If it has the same version number as the referenced DLL, the GAC gets used. 如果它与引用的DLL具有相同的版本号,则使用GAC。

If you increment the version number, rebuild the website referencing the new version number, put the new version in the /bin directory, then that DLL will be used. 如果您增加版本号,请重新引用引用新版本号的网站,将新版本放在/ bin目录中,然后将使用该DLL。

If you do not want to change the version number, you're pretty much out of luck. 如果您不想更改版本号,那么您将非常幸运。

When .NET loads strong named assemblies, first it tries to decide what version number to use. 当.NET加载强命名程序集时,首先它会尝试确定要使用的版本号。 It does this via the reference first, then it looks for publisher policies , then it looks for binding redirects in the configuration file. 它首先通过引用执行此操作,然后查找发布者策略 ,然后在配置文件中查找绑定重定向

After it does this, it looks for the assembly in the GAC, then in any codebase specified , then it probes various file system folders for the DLL. 执行此操作后,它会在GAC中查找程序集,然后在指定的任何代码库中查找,然后它会探测DLL的各种文件系统文件夹。 If at any one of those steps it finds the right version assembly, it stops. 如果在任何一个步骤中找到正确的版本程序集,它就会停止。

If you are not changing the version number of your strong named assembly, .NET will find the original one in the GAC and stop looking. 如果您不更改强命名程序集的版本号,.NET将在GAC中找到原始版本并停止查找。 Note that because it stops when it finds one, and because looking in the GAC is first, specifying a codebase for your assembly will do no good unless you also specify a new version number. 请注意,因为它在找到一个时停止,并且因为在GAC中查找是第一个,所以为程序集指定代码库将没有任何好处,除非您还指定了新的版本号。

I have been able to override the GAC with the assembly in the \\bin folder using the <codebase> Element. 我已经能够使用<codebase>元素在\\ bin文件夹中使用程序集覆盖GAC。

By specifying <codebase version="1.2.3.4" href="/bin/MyAssembly.dll" /> in my web.config file I can tell my application to use this version rather than the version specified in the GAC. 通过在我的web.config文件中指定<codebase version="1.2.3.4" href="/bin/MyAssembly.dll" /> ,我可以告诉我的应用程序使用此版本而不是GAC中指定的版本。

You may also want to take a look at the <probing> Element for specifying assembly locations? 您可能还想查看<probing>元素以指定装配位置?

I think I might be saying the same think as Adam Sills, but re-worded it for my understanding. 我想我可能会像亚当·西尔斯那样说出来,但为了我的理解而重新措辞。 Through my own testing, looks like this is what happens: 通过我自己的测试,看起来是这样的:

  • If your app is compiled with version 1.0.0.0 and 1.0.0.1 is in the GAC, then you can omit the .dll from your /bin. 如果您的应用程序是使用版本1.0.0.0编译的,而1.0.0.1是在GAC中,那么您可以省略/ bin中的.dll。
  • If your app is compiled with version 1.0.0.1 and 1.0.0.0 is in the GAC, then you MUST place the .dll in your /bin to ignore the GAC. 如果您的应用程序是使用版本1.0.0.1编译的,而1.0.0.0是在GAC中,那么您必须将.dll放在/ bin中以忽略GAC。 A error will occur if the GAC version is older than the required version of your app, unless you include the newer version in your /bin. 如果GAC版本早于应用程序的所需版本,则会出现错误,除非您在/ bin中包含较新版本。

I hope this is correct... 我希望这是正确的......

You can view binding information in the log file using the Assembly Binding Log Viewer (Fuslogvw.exe), which is included in the Windows Software Development Kit (SDK). 您可以使用Windows软件开发工具包(SDK)中包含的程序集绑定日志查看器(Fuslogvw.exe)在日志文件中查看绑定信息。

s 小号

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

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