如何防止.NET应用程序从GAC加载/引用程序集? [英] How to prevent a .NET application from loading/referencing an assembly from the GAC?

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

问题描述

我可以以某种方式(在Visual Studio中进行设置)配置.NET应用程序,使其引用本地程序集(不在 GAC ),而不是GAC中的程序集,尽管两个程序集具有相同的名称和相同的版本?

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?

推荐答案

如果两个程序集都是强命名的(带符号),则CLR将始终从GAC加载。

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. 确定正确的位置程序集版本,方法是检查适用的
    配置文件,包括
    应用程序配置文件,
    发布者策略文件和计算机
    配置文件。如果
    配置文件位于
    远程计算机上,则运行时必须
    首先找到并下载应用程序
    配置文件。

  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.

检查程序集名称之前是否已绑定,如果是,则
使用先前加载的程序集。
如果先前加载
程序集的请求失败,则该请求将立即使
失败,而不会尝试加载
程序集。

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.

检查全局程序集缓存。如果在此处找到该程序集,则
运行时将使用此程序集。

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

该程序集的探针(...省略了一些材料...)

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.

因此,如果您有能力从本地程序集中删除签名,则应用程序将使用它代替GAC中的签名。

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.

来自Sc的博客条目ott Hanselman 还对绑定过程进行了很好的概述。

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

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

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