简体   繁体   English

是否可以保证同时安装两个(或更多)版本的.NET Framework?

[英]Is it guaranteed for two (or more) versions of the .NET Framework to be installed side by side?

Based on many articles I have read, I came to the conclusion that it is not guaranteed for a .NET Framework to be 100% backward compatible with the previous versions. 根据我读过的许多文章,我得出的结论是,不能保证.NET Framework可以与以前的版本100%向后兼容。 So my question is: is it guaranteed for two (or more) versions of the .NET Framework to be installed side by side without any problems (is this documented somewhere by Microsoft)? 所以我的问题是:是否可以确保两个(或更多)版本的.NET Framework并排安装而没有任何问题(此文件是否由Microsoft记录在案)?

For example, can .NET 1.1 be installed side by side with .NET 4.5, or will I have to re-compile my project to work on .NET 4.5? 例如,.NET 1.1是否可以与.NET 4.5并排安装,还是需要重新编译我的项目才能在.NET 4.5上运行?

There's a difference between the Framework version and the runtime version. Framework版本和运行时版本之间有区别。 You can have different runtimes operate side-by-side without interfering if your application is properly marked with the expected runtime in its configuration file. 如果应用程序在其配置文件中正确标记了预期的运行时,则可以使不同的运行时并排运行,而不会产生干扰。

Programs written for a particular runtime (eg 1.1, 2.0, 4.0) can run independently against their given framework with no side effects from the other frameworks. 为特定运行时(例如1.1、2.0、4.0)编写的程序可以针对其给定的框架独立运行,而不会受到其他框架的影响。 That being said, you must modify your config file to ensure that a .NET 2.0 application runs with the .NET 2.0 CLR when the 4.0 CLR is installed on the machine 话虽如此,您必须修改配置文件以确保在计算机上安装4.0 CLR时,.NET 2.0应用程序与.NET 2.0 CLR一起运行。

The CLR's are affected by the version of the Framework installed on the machine. CLR受计算机上安装的Framework版本的影响。 For example, 4.0 and 4.5 both run with the 4.0 CLR and having 4.5 installed introduces some incompatibilities. 例如,4.0和4.5都与4.0 CLR一起运行,并且安装了4.5会引入一些不兼容性。 That being said, these issues are usually very specific and most applications will not be affected by them. 话虽如此,这些问题通常是非常具体的,并且大多数应用程序不会受到它们的影响。

Here's Microsoft's page on compatibility between Framework versions. 这是Microsoft关于 Framework版本之间兼容性的页面

Your question seems to be in two parts: 您的问题似乎分为两部分:

  1. Are .NET Frameworks backward compatible? .NET Framework是否向后兼容?
  2. Can you install more than one .NET Framework at the same time on the same computer? 您可以在同一台计算机上同时安装多个.NET Framework吗?

Yes you can install multiple versions of the ".NET Framework" at the same time without problems. 是的,您可以同时安装多个版本“ .NET Framework” ,而不会出现问题。 Whether or not an app runs as expected is a different story as explained in the MSDN doco. 应用程序是否按预期运行是一个不同的故事,如MSDN doco中所述。

MSDN: MSDN:

You can load multiple versions of the .NET Framework on a single computer at the same time . 您可以在一台计算机上同时加载多个版本.NET Framework This means that you can install the .NET Framework without having uninstall previous versions Tell me more 这意味着您可以安装.NET Framework,而无需卸载以前版本的告诉我更多

...and ...和

In general, you should not uninstall any versions of the .NET Framework that are installed on your computer . 通常, 您不应卸载计算机上安装的任何.NET Framework版本 There are two reasons for this: If an application that you use depends on a specific version of the .NET Framework, that application may break if that version is removed. 造成这种情况的原因有两个:如果您使用的应用程序依赖于.NET Framework的特定版本,则如果删除该版本,该应用程序可能会损坏。 Some versions of the .NET Framework are in-place updates to earlier versions. .NET Framework的某些版本是对早期版本的就地更新。 For example, the .NET Framework 3.5 is an in-place update to version 2.0, and the .NET Framework 4.5.2 is an in-place update to versions 4, 4.5, and 4.5.1. 例如,.NET Framework 3.5是对2.0版的就地更新,而.NET Framework 4.5.2是对4、4.5和4.5.1的就地更新。 Golly, tell me more 宝贝,告诉我更多

Backward Compatibility 向后兼容

Though newer versions of the framework are generally backward compatible (with respect to contracts) there may be unforseen behavioural changes visible at runtime. 尽管较新版本的框架通常向后兼容(相对于合同而言),但在运行时可能会出现无法预见的行为更改。

As MSDN states: 正如MSDN所述:

The .NET Framework 4.5 and its point releases are backward-compatible with apps that were built with earlier versions of the .NET Framework. .NET Framework 4.5及其指向发行版与使用.NET Framework早期版本构建的应用程序向后兼容。 In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5 换句话说,使用早期版本构建的应用和组件无需修改即可在.NET Framework 4.5上运行。

...however: ...然而:

In practice, this compatibility can be broken by seemingly inconsequential changes in the .NET Framework and changes in programming techniques. 实际上, 可以通过.NET Framework中似乎无关紧要的更改和编程技术的更改来破坏这种兼容性。 For example, performance improvements in the .NET Framework 4 can expose a race condition that did not occur on earlier versions. 例如,.NET Framework 4中的性能改进可以揭示早期版本中没有出现的竞争条件 More 更多

So an app without appropriate config may be upscaled to use later versions of libraries leading to undesirable results. 因此,没有适当配置的应用程序可能会升级为使用更高版本的库,从而导致不良结果。 Sadly nothing can be done for a 4.0 app if .NET 4.5 is installed because the actual CLR was changed. 遗憾的是,如果安装了.NET 4.5,则对于4.0应用程序将无法执行任何操作,因为实际的CLR已更改。 More... 更多...

As Rick Strahl writes: 正如里克·斯特拉尔(Rick Strahl)写道:

Note that this in-place replacement is very different from the side by side installs of .NET 2.0 and 3.0/3.5 which all ran on the 2.0 version of the CLR. 请注意,此就地替换与.NET 2.0和3.0 / 3.5的并行安装有很大不同,.NET 2.0和3.0 / 3.5均在CLR的2.0版本上运行。 The two 3.x versions were basically library enhancements on top of the core .NET 2.0 runtime. 这两个3.x版本基本上是在核心.NET 2.0运行时之上的库增强。 Both versions ran under the .NET 2.0 runtime which wasn't changed (other than for security patches and bug fixes) for the whole 3.x cycle. 这两个版本都在.NET 2.0运行时下运行,整个3.x周期都未更改(安全补丁和错误修复除外)。 The 4.5 update instead completely replaces the .NET 4.0 runtime and leaves the actual version number set at v4.0.30319. 而4.5更新完全替代了.NET 4.0运行时 ,并将实际版本号设置为v4.0.30319。 More... 更多...

So far, we only see the following frameworks can be run side by side, 到目前为止,我们仅看到以下框架可以并行运行,

  • .NET 1.x (already obsolete, so don't want to comment more) .NET 1.x(已经过时了,所以不想多评论)
  • .NET 2.0/3.0/3.5 as a whole .NET 2.0 / 3.0 / 3.5整体
  • .NET 4.0/4.5/4.5.1/4.6 as a whole 整个.NET 4.0 / 4.5 / 4.5.1 / 4.6
  • .NET Core .NET核心

And you can see there is no guarantee from Microsoft whether a new version can be installed side by side or be an in-place upgrade of the previous version, and it really depends on what feature sets the new version brings. 而且您可以看到Microsoft无法保证可以并排安装新版本还是可以对旧版本进行就地升级,这实际上取决于新版本带来的功能。

We might observe some general rules (such as the frameworks with the same CLR version should be in-place upgrade), but that's still not something guaranteed by Microsoft, and can be broken by a future framework release. 我们可能会观察到一些通用规则(例如,具有相同CLR版本的框架应该就地升级),但是Microsoft仍然不能保证这一点,并且将来的框架版本可能会破坏这些规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM