.NET 2.0 程序集可以在 .NET 4.0 下运行吗?

发布于 2024-11-29 18:58:46 字数 262 浏览 0 评论 0原文

我开发了一个由多个程序集组成的 .NET 解决方案,其中大多数是针对 .NET Framework 2.0 版本的小型帮助程序集。其余程序集是 MVC 3 Web 应用程序,它们必须面向 .NET Framework 4.0 版本。除了 .NET 和 MVC 框架之外,我的解决方案没有其他外部依赖项。

我的问题如下:当我向客户部署此解决方案时,我是否必须部署两个版本的 .NET Framework,还是可以只部署 4.0 版本? .NET 2.0 程序集可以在 .NET 4.0 下运行吗?

I have developed a .NET solution that consists of several assemblies, most of which are small helper assemblies that target version 2.0 of the .NET Framework. The remaining assemblies are MVC 3 Web applications, which must necessarily target version 4.0 of the .NET Framework. My solution has no other external dependencies besides the .NET and MVC Frameworks.

My question is the following: When I deploy this solution to customers, do I have to deploy both versions of the .NET Framework, or can I just deploy version 4.0? Can .NET 2.0 assemblies run under .NET 4.0?

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

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

发布评论

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

评论(4

瞳孔里扚悲伤 2024-12-06 18:58:46

是的,嵌入在 .NET 2.0 程序集中的依赖项会自动转换为其 4.0 版本。但它运行时使用的是从未测试过的那些程序集的版本。它们高度兼容,但包含多个错误修复,以及您可能在不知不觉中依赖的错误。没有人能给你100%的保证。

试试吧。

Yes, the dependencies embedded in the assembly on .NET 2.0 assemblies are automatically translated to their 4.0 version. But it runs with a version of those assemblies it has never been tested on. They are highly compatible but contain several bug fixes, bugs that you might unknowingly have a dependency on. Nobody can give you a 100% guarantee.

Just try it.

香草可樂 2024-12-06 18:58:46

您只需要最新版本。它是向下兼容的。

You only need the latest version. It's downward compatible.

憧憬巴黎街头的黎明 2024-12-06 18:58:46

答案是肯定的,为.NET 2.0开发的程序集将在.NET 4.0下正确运行

The answer is yes, assemblies developed for .NET 2.0 will run correctly under .NET 4.0

二智少女 2024-12-06 18:58:46

是和否(至少对于.Net 4.5)。虽然它向后兼容,但默认情况下是在关联的 .Net 版本上运行代码,如所述 此处

.NET Framework 4.5 及其单点版本向后兼容使用早期版本的 .NET Framework 构建的应用程序。换句话说,使用早期版本构建的应用程序和组件无需修改即可在 .NET Framework 4.5 上运行。但是,默认情况下,应用程序在为其开发的公共语言运行时版本上运行,因此您可能必须提供配置文件以使您的应用程序能够在 .NET Framework 4.5 上运行。有关详细信息,请参阅本文前面的“应用程序的版本兼容性”部分。

添加 MyLovely.exe.config 文件后一切正常:

<configuration>
  <startup>
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

Yes and no (at least for .Net 4.5). While it is backwards compatible, the default is to run the code on the associated .Net version as noted here:

The .NET Framework 4.5 and its point releases are backward-compatible with apps that were built with earlier versions of the .NET Framework. In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5. However, by default, apps run on the version of the common language runtime for which they were developed, so you may have to provide a configuration file to enable your app to run on the .NET Framework 4.5. For more information, see the Version compatibility for apps section earlier in this article.

After adding a MyLovely.exe.config file everything worked fine:

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