*为什么* Visual Studio 不允许您在 GAC 中引用程序集?

发布于 2024-10-04 09:47:17 字数 797 浏览 0 评论 0原文

有几个问题已经回答了如何,或者更准确地说,如何解决此 Visual Studio 限制:

“添加引用”对话框中缺少 GAC 程序集 如何在来自 Visual Studio 的 GAC?

MSDN 文档 虽然说:

您无法添加来自 全局程序集缓存 (GAC),原样 严格是运行时的一部分 环境。

所以看来 Visual Studio 团队是故意这样做的。也许他们这样做是为了让你不伤害自己?使用 VS 扩展像这样?我错过了什么吗?

只需与社区再次核实,欣赏您的想法。

There have been several questions that have answered the HOW or more precisely how to get around this Visual Studio limitation:

GAC Assembly Missing in Add Reference dialog
How can I reference a dll in the GAC from Visual Studio?

The MSDN documentation though says:

You cannot add references from the
Global Assembly Cache (GAC), as it is
strictly part of the run-time
environment.

So it seems that the Visual Studio team did this on purpose. Maybe they did this so you don't hurt yourself? What best practice am I violating by referencing an assembly in the GAC using an VS extension like this? Am I missing something?

Just double-checking with the community, appreciate your thoughts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

护你周全 2024-10-11 09:47:17

使用 Sharp Develop(.NET 的开源 IDE),您可以添加 GAC 引用,使用 .NET 4,您可以添加 GAC 引用。添加 GAC 参考绝对不会伤害自己。我没有收到使用它的开发人员的任何负面反馈。

很快此扩展将具有更多性感功能。

With Sharp Develop (which is an open source IDE for .NET) you could add GAC references, with .NET 4 you could add GAC references. You definitely won't hurt yourself by adding GAC references. I don't have any negative feedback from developers using it.

Soon this extension will have more sexy features.

夜唯美灬不弃 2024-10-11 09:47:17

它实际上并不能阻止你这样做。特别是对于 .NET 4.0,您可以使用“浏览”选项卡访问 c:\windows\microsoft.net\ assembly。 4.0 中不包含阻止您通过 shell 对话框访问 .NET 2.0 GAC 的 shell 扩展处理程序。

但是,这是一个非常糟糕的主意。 GAC 是部署实施细节,您不能假设您的 GAC 的内容将与另一台计算机上的内容匹配。只有参考程序集才能为您提供一组稳定的类型定义,这些定义在您通过 Windows Update 获取安全更新时不会发生变化。

这与 .NET 4.0 更相关。它的参考组件很特殊。它们不再是您可能在 GAC 或 c:\windows\microsoft.net 中找到的程序集的副本。它们仅包含元数据,不包含 IL。这允许 Microsoft 部署更改程序集中公共类型的更新。 .NET 2.0 服务包中出现严重错误(例如,WaitHandle.WaitOne(int))。

It doesn't actually stop you from doing this. In particular for .NET 4.0, you can use the Browse tab to access c:\windows\microsoft.net\assembly. The shell extension handler that stops you from accessing the .NET 2.0 GAC through the shell dialogs isn't included for 4.0

But yeah, that's a really bad idea. The GAC is a deployment implementation detail, you cannot presume that the content of your GAC will match the content on another machine. Only a reference assembly can give you a stable set of type definitions that don't change when, say, you get a security update through Windows Update.

This is even more relevant for .NET 4.0. Its reference assemblies are special. They are no longer a copy of the assemblies you might find in the GAC or in c:\windows\microsoft.net. They only contain metadata, no IL. This allows Microsoft to deploy updates that change the public types in the assemblies. Something that went badly wrong in the .NET 2.0 service packs (WaitHandle.WaitOne(int) for example).

王权女流氓 2024-10-11 09:47:17

由于 GAC 可以拥有给定程序集的多个版本,因此它很快就会变得非常复杂。要求您希望引用的版本的副本位于普通文件夹中会更容易。

(大多数时候,您不应该使用 GAC,因为它与 COM 时代的 Register 一样麻烦。)

Because the GAC can have more than one version of a given Assembly, so it will get very complex very quickly. It is easier to require that a copy of the version you wish to reference is in a normal folder.

(Most of the time you should not be using the GAC as it is as much of a pain as the Register was in COM’s days.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文