.NET 4.0 有一个新的 GAC,为什么?

发布于 2024-08-29 06:20:22 字数 226 浏览 2 评论 0 原文

%windir%\Microsoft.NET\ assembly\ 是新的 GAC 。这是否意味着现在我们必须管理两个 GAC,一个用于 .NET 2.0-3.5 应用程序,另一个用于 .NET 4.0 应用程序?

问题是,为什么?

%windir%\Microsoft.NET\assembly\ is the new GAC. Does it mean now we have to manage two GACs, one for .NET 2.0-3.5 applications and the other for .NET 4.0 applications?

The question is, why?

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

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

发布评论

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

评论(4

遥远的她 2024-09-05 06:20:22

是的,因为有 2 个不同的全局程序集缓存 (GAC),您必须单独管理它们。

在 .NET Framework 4.0 中,GAC 经历了一些更改。 GAC 被分成两部分,每个 CLR 一个。

用于 .NET Framework 2.0 和 .NET Framework 3.5 的 CLR 版本是 CLR 2.0。前两个框架​​版本中无需拆分 GAC。 Net Framework 4.0 中破坏旧应用程序的问题。

为了避免 CLR 2.0 和 CLR 4.0 之间的问题,GAC 现在分为每个运行时的私有 GAC。主要变化是 CLR v2.0 应用程序现在无法在 GAC 中看到 CLR v4.0 程序集。

来源

为什么?

看来这是因为 .NET 4.0 中发生了 CLR 更改,但 2.0 到 3.5 中没有更改。 1.1 到 2.0 CLR 也发生了同样的事情。看来 GAC 能够存储不同版本的程序集,只要它们来自同一个 CLR。他们不想破坏旧的应用程序。

请参阅 MSDN 中有关 4.0 中的 GAC 更改的信息

例如,如果 .NET 1.1 和 .NET 2.0 共享相同的 GAC,则从该共享 GAC 加载程序集的 .NET 1.1 应用程序可能会获取 .NET 2.0 程序集,从而破坏 .NET 1.1 应用程序< /p>

用于 .NET 的 CLR 版本
框架 2.0 和 .NET 框架 3.5
是 CLR 2.0。其结果是,有
前两次不需要
发布框架以拆分 GAC。
打破旧的问题(在这
案例,.NET 2.0)应用程序
在 Net Framework 4.0 中重新出现
至此CLR 4.0发布了。因此,
以避免之间的干扰问题
CLR 2.0 和 CLR 4.0,GAC 现在
分成每个人的私人 GAC
运行时。

随着 CLR 在未来版本中的更新,您可以期待同样的事情。如果仅语言发生变化,那么您可以使用相同的 GAC。

Yes since there are 2 distinct Global Assembly Cache (GAC), you will have to manage each of them individually.

In .NET Framework 4.0, the GAC went through a few changes. The GAC was split into two, one for each CLR.

The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. There was no need in the previous two framework releases to split GAC. The problem of breaking older applications in Net Framework 4.0.

To avoid issues between CLR 2.0 and CLR 4.0 , the GAC is now split into private GAC’s for each runtime.The main change is that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC.

Source

Why?

It seems to be because there was a CLR change in .NET 4.0 but not in 2.0 to 3.5. The same thing happened with 1.1 to 2.0 CLR. It seems that the GAC has the ability to store different versions of assemblies as long as they are from the same CLR. They do not want to break old applications.

See the following information in MSDN about the GAC changes in 4.0.

For example, if both .NET 1.1 and .NET 2.0 shared the same GAC, then a .NET 1.1 application, loading an assembly from this shared GAC, could get .NET 2.0 assemblies, thereby breaking the .NET 1.1 application

The CLR version used for both .NET
Framework 2.0 and .NET Framework 3.5
is CLR 2.0. As a result of this, there
was no need in the previous two
framework releases to split the GAC.
The problem of breaking older (in this
case, .NET 2.0) applications
resurfaces in Net Framework 4.0 at
which point CLR 4.0 released. Hence,
to avoid interference issues between
CLR 2.0 and CLR 4.0, the GAC is now
split into private GACs for each
runtime.

As the CLR is updated in future versions you can expect the same thing. If only the language changes then you can use the same GAC.

动听の歌 2024-09-05 06:20:22

我还想知道为什么 2 GAC 并发现以下 Mark Miller 的解释,位于 .NET 4.0 有 2 个全局程序集缓存 (GAC)

马克·米勒说...
2010 年 6 月 28 日下午 12:13

谢谢
帖子。 “干扰问题”是
故意含糊其辞。当时
写作时,问题仍然存在
调查过,但很明显
有几个破碎的场景。

例如,某些应用程序使用
加载Assemby.LoadWithPartialName
程序集的最高版本。如果
最高版本是用
v4,然后 v2(3.0 或 3.5)应用程序可以
不加载它,应用程序就会崩溃,
即使有一个版本
会起作用的。本来,我们
在其下对 GAC 进行分区
原来的位置,但这导致
windows升级的一些问题
场景。这两个都涉及到代码
已经发货了,所以我们搬家了
我们的(按版本划分的 GAC 到
另一个地方。

这应该不会对大多数人产生任何影响
应用程序,并且不添加任何
维护负担。两个地点
只能被访问或修改
使用原生 GAC API,处理
与预期的分区。这
这表面的地方
通过公开路径的 API
GAC,例如 GetCachePath,或
检查加载的 mscorlib 的路径
到托管代码中。

值得注意的是,我们修改了GAC
我们也发布 v2 时的位置
当我们将架构引入为
程序集标识的一部分。那些
添加了 GAC_MSIL、GAC_32 和 GAC_64,
尽管一切仍处于
%windir%\程序集。不幸的是,那
不是此版本的选项。

希望它对未来的读者有所帮助。

I also wanted to know why 2 GAC and found the following explanation by Mark Miller in the comments section of .NET 4.0 has 2 Global Assembly Cache (GAC):

Mark Miller said...
June 28, 2010 12:13 PM

Thanks for
the post. "Interference issues" was
intentionally vague. At the time of
writing, the issues were still being
investigated, but it was clear there
were several broken scenarios.

For instance, some applications use
Assemby.LoadWithPartialName to load
the highest version of an assembly. If
the highest version was compiled with
v4, then a v2 (3.0 or 3.5) app could
not load it, and the app would crash,
even if there were a version that
would have worked. Originally, we
partitioned the GAC under it's
original location, but that caused
some problems with windows upgrade
scenarios. Both of these involved code
that had already shipped, so we moved
our (version-partitioned GAC to
another place.

This shouldn't have any impact to most
applications, and doesn't add any
maintenance burden. Both locations
should only be accessed or modified
using the native GAC APIs, which deal
with the partitioning as expected. The
places where this does surface are
through APIs that expose the paths of
the GAC such as GetCachePath, or
examining the path of mscorlib loaded
into managed code.

It's worth noting that we modified GAC
locations when we released v2 as well
when we introduced architecture as
part of the assembly identity. Those
added GAC_MSIL, GAC_32, and GAC_64,
although all still under
%windir%\assembly. Unfortunately, that
wasn't an option for this release.

Hope it helps future readers.

深爱成瘾 2024-09-05 06:20:22

这没有多大意义,原来的 GAC 已经能够存储不同版本的程序集了。并且没有理由假设程序会意外引用错误的程序集,所有 .NET 4 程序集的 [AssemblyVersion] 都已升至 4.0.0.0。新的进程内并排功能不应改变这一点。

我的猜测:已经有太多的 .NET 项目违反了“永远不要直接引用 GAC 中的任何内容”规则。我已经在这个网站上看到过好几次了。

避免破坏这些项目的唯一方法是:移动 GAC。向后兼容对于微软来说是神圣的。

It doesn't make a lot of sense, the original GAC was already quite capable of storing different versions of assemblies. And there's little reason to assume a program will ever accidentally reference the wrong assembly, all the .NET 4 assemblies got the [AssemblyVersion] bumped up to 4.0.0.0. The new in-process side-by-side feature should not change this.

My guess: there were already too many .NET projects out there that broke the "never reference anything in the GAC directly" rule. I've seen it done on this site several times.

Only one way to avoid breaking those projects: move the GAC. Back-compat is sacred at Microsoft.

孤千羽 2024-09-05 06:20:22

在 .NET Framework 4.0 中,GAC 经历了一些更改。 GAC 被分成两部分,每个 CLR 一个。

用于 .NET Framework 2.0 和 .NET Framework 3.5 的 CLR 版本是 CLR 2.0。前两个框架​​版本中无需拆分 GAC。 Net Framework 4.0 中破坏旧应用程序的问题。

为了允许较旧的(32 位、单线程)应用程序运行,同时也允许较新的(64 位,可能是多线程)应用程序运行并避免 CLR 2.0 和 CLR 4.0 之间的问题,GAC 需要分为每个运行时的私有 GAC。主要变化是,由于线程安全问题,CLR v2.0 应用程序现在无法在 GAC 中看到 CLR v4.0 程序集。

这种拆分还允许对整个 .Net 进行版本升级/更新,而不会牺牲向后兼容性。

In .NET Framework 4.0, the GAC went through a few changes. The GAC was split into two, one for each CLR.

The CLR version used for both .NET Framework 2.0 and .NET Framework 3.5 is CLR 2.0. There was no need in the previous two framework releases to split GAC. The problem of breaking older applications in Net Framework 4.0.

To allow older (32-bit, single-threaded) apps to function, while also allowing newer (64-bit, possibly multi-threaded) ones to work AND avoiding issues between CLR 2.0 and CLR 4.0, the GAC needed to be split into private GAC’s for each runtime. The main change is that CLR v2.0 applications now cannot see CLR v4.0 assemblies in the GAC, because of Thread-Safety concerns.

This split also allows for version upgraded/updates for .Net as a whole, without sacrificing backwards compatibility.

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