如何prevent一个.NET应用程序使用的程序集从GAC? [英] How to prevent a .NET application to use an assembly from the GAC?

查看:166
本文介绍了如何prevent一个.NET应用程序使用的程序集从GAC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以配置.NET应用程序的方式(在Visual Studio中设置),它引用了本地组件(不是在的 GAC ),而不是GAC内的程序集,尽管这两个组件具有相同的名称和相同的版本?

解决方案

如果这两个组件都是强名称(签字),CLR将始终从GAC加载。

下面是运行时用来解析程序集引用(步骤从运行时如何定位程序集

  
      
  1. 通过审查适用确定正确的程序集的版本   配置文件,包括   应用程序配置文件,   出版商策略文件,机器   配置文件。如果   配置文件位于一个   远程机器上,运行时必须   找到并下载应用程序   配置文件中的第一。

  2.   
  3. 检查程序集名称是否已绑定到之前,如果是这样,   使用pviously加载的程序集的$ P $。   如果previous请求加载   集失败,请求失败   立即而不尝试加载   装配。

  4.   
  5. 检查全局程序集缓存。如果组件发现那里,   运行时使用该组件。

  6.   
  7. 探头的组件(...一些物质省略......)

  8.   

由于在同一篇文章后说:

  

没有版本检测不强名称的程序集,也没有运行时   为您在为没有强名称的程序集全局程序集缓存。

所以,如果你能负担得起删除该地方议会签署,该应用程序将使用而不是一个在GAC吧。

有关更详细的比你很可能永远希望有关运行时绑定机制,请参见苏珊娜·库克的博客

<一个href="http://www.hanselman.com/blog/FusionLoaderContextsUnableToCastObjectOfTypeWhateverToTypeWhatever.aspx">This从斯科特Hanselman的博客条目还提供了结合过程的一个很好的概述。

Can I configure a .NET application in a way (settings in Visual Studio) that it references a "local" assembly (not in GAC) instead of an assembly within the GAC, although both assemblies have the same name and the same version?

解决方案

If both assemblies are strong-named (signed), the CLR will always load from the GAC.

Here are the steps the runtime uses to resolve assembly references (from How the Runtime Locates Assemblies):

  1. Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.

  2. Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If a previous request to load the assembly failed, the request fails immediately without attempting to load the assembly.

  3. Checks the global assembly cache. If the assembly is found there, the runtime uses this assembly.

  4. Probes for the assembly (... some material omitted ...)

As stated later in that same article:

There is no version checking for assemblies without strong names, nor does the runtime check in the global assembly cache for assemblies without strong names.

So if you can afford to remove signing from the local assembly, the application will use it instead of the one in the GAC.

For more detail than you could probably ever want about the runtime-binding mechanisms, see Suzanne Cook's blog.

This blog entry from Scott Hanselman also provides a great overview of the binding process.

这篇关于如何prevent一个.NET应用程序使用的程序集从GAC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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