vue 什么是就地复用_.NET版本控制和多目标-.NET 4.5是就地升级到.NET 4.0

本文讨论了.NET Framework的版本控制,重点是.NET 4.5作为.NET 4的就地升级。作者指出,虽然.NET 4.5在CLR上进行了更新和库增强,但并未引入全新的CLR,这意味着主要版本升级通常涉及新CLR,而次要版本则涉及错误修复和新库。此外,文章解释了.NET 4.5与.NET 4之间的兼容性,并强调在开发过程中,Visual Studio能够处理不同版本的.NET框架,确保安全地针对.NET 4进行开发。
摘要由CSDN通过智能技术生成
vue 什么是就地复用

vue 什么是就地复用

Say what you will about the past ridiculousness of .NET Framework versioning, since the confusion of .NET 3.5SP1 they've  been trying to get it right. It's not the magic of Java Version 6 Update 31 (build 1.6.0_31-b05) but it's a start. O_o

说说您过去对.NET Framework版本控制的可笑之处,因为.NET 3.5SP1的混乱,他们一直在努力使其正确。 这不是Java版本6 Update 31(内部版本1.6.0_31-b05)的魔力,而是一个开始。 O_o

Back in July of 2011 I wrote a post on Issues with .NET and Microsoft Product Versioning that got the attention of some folks. I was most concerned about some "platform updates" to .NET 4 and the way they were named. Meetings were had and those small updates now have simpler names versions like NET 4.0.1, etc.

早在2011年7月,我写了一篇有关.NET和Microsoft产品版本问题的文章,引起了一些人的注意。 我最担心的是对.NET 4的一些“平台更新”以及它们的命名方式。 开会了,那些小的更新现在有了更简单的名称版本,例如NET 4.0.1等。

I'm not going to tell you it's not confusing today. I do think that things are getting better and becoming less confusing. .NET 4.5 is a step in the right direction of transparency in versioning.

我不会告诉你今天没有混乱。 我确实认为情况正在变得越来越好,变得越来越混乱。 .NET 4.5是朝着正确的版本控制方向迈出的一步。

The .NET Framework can version in two ways. There are "side by side installs" and there are "in place upgrades." A major version means side-by-side and a minor version means in-place.

.NET Framework可以通过两种方式进行版本控制。 有“并行安装”和“就地升级”。 主版本表示并排,次版本表示就地。

Side-by-side means that different versions of .NET can live together on the same machine.

并排表示.NET的不同版本可以在同一台计算机上一起生活。

Diagram: .NET CLRs can live side by side

In-place upgrade means that the CLR is the same but new libraries are added as well as bug fixes and performance improvements:

就地升级意味着CLR相同,但是添加了新库以及错误修复和性能改进:

Diagram: .NET 4.5 builds on top of .NET 4

There's been some concern about how .NET 4.5 is an "in-place upgrade" of .NET 4. That means .NET 4.5 is still the v4CLR and adds new libraries as well as improvements to the core CLR itself.

.NET 4.5如何成为.NET 4的“就地升级”,这引起了一些关注。这意味着.NET 4.5仍然是v4CLR,并增加了新的库以及对核心CLR本身的改进。

Rick Strahl said on his blog:

里克·斯特拉尔(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. The two 3.x versions were basically library enhancements on top of the core .NET 2.0 runtime. 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. The 4.5 update instead completely replaces the .NET 4.0 runtime and leaves the actual version number set at v4.0.30319.

请注意,这种就地替换与.NET 2.0和3.0 / 3.5的并行安装有很大不同,.NET 2.0和3.0 / 3.5均在CLR的2.0版本上运行。 这两个3.x版本基本上是在核心.NET 2.0运行时之上的库增强。 这两个版本都在.NET 2.0运行时下运行,整个3.x周期都未更改(安全补丁和错误修复除外)。 而4.5更新完全替代了.NET 4.0运行时,并将实际版本号设置为v4.0.30319。

Rick has a great post with a lot of detail and information. However, respectfully, I don't think .NET 4.5 vs. .NET 4 is as different as Rick implies. In fact .NET 3 and .NET 3.5 both upgraded the system (and CLR) in place as well.

里克(Rick)的帖子很棒,包含很多细节和信息。 但是,恭喜,我认为.NET 4.5与.NET 4并没有Rick所暗示的那么不同。 实际上,.NET 3和.NET 3.5都已对系统(和CLR)进行了升级。

Perhaps if 3 and 3.5 were called .NET 2.5 and .NET 2.8 it would have made more sense. The community is always concerned about breaking changes, much like we are here with .NET 4 and .NET 4.5. Unfortunately reality and marketing names haven't always matched, but going forward I think we all agree that:

也许如果将3和3.5分别称为.NET 2.5和.NET 2.8,它将更有意义。 社区始终关心突破性变化,就像我们在使用.NET 4和.NET 4.5一样。 不幸的是,现实和营销名称并非总是匹配,但展望未来,我认为我们都同意:

  • Major Version = New CLR

    主要版本=新CLR
  • Minor Version = Bug fixes, new libraries

    次要版本=错误修复,新库
  • Revision = Bug fixes, no breaking changes, small improvements

    修订版=修正了错误,没有重大更改,做了很小的改进

.NET 4.5 is not a radically different side-by-side CLR. A new CLR would be a theoretical .NET 5 In my opinion.

.NET 4.5并不是完全不同的并排CLR。 我认为,新的CLR应该是理论上的.NET 5。

Could something break with .NET 4.5? This is why it's in beta now, so now is the time to speak up. It's possible something could break but unlikely according the .NET Blog. Here are the known .NET 4.5 breaking changes - most are pretty obscure. The kinds of breaking changes I've seen myself in the wild have been primarily when folks are relying on reflection or internal data structures. These internals aren't public contracts so they may have changed. I realize that when a change breaks YOU it feels like a situation when "100% of applications will break....mine did!" situation. It sucks, but in fact there are minimal breaking changes in .NET 4.5.

.NET 4.5可能会破坏某些功能吗? 这就是为什么它现在处于测试阶段,所以现在该是时候了。 .NET Blog称,有可能发生某些故障,但可能性很小。 这是已知的.NET 4.5重大更改-大部分都是晦涩的。 我在野外看到的突破性变化主要是当人们依靠反射或内部数据结构时。 这些内部不是公共合同,因此它们可能已更改。 我意识到,当变更破坏了您的感觉时,就像是“ 100%的应用程序将破坏.... mine破坏了!”的情况。 情况。 它很烂,但是实际上.NET 4.5中的更改很少。

Can I get .NET 2.0, 3.5, 4 and 4.5 apps all running together on my system? Yes.

我可以在系统上同时运行.NET 2.0、3.5、4和4.5应用程序吗? 是。

Can I develop apps with different versions with Visual Studio 11 Beta? Sure, you can multi-target all these versions and even plugin more targeting packs. I'll do a blog post later this week on Portable Libraries, a new version in .NET 4.5 that makes creating libraries for any CLR (including Xbox, Phone, Mono and others).

我可以使用Visual Studio 11 Beta开发具有不同版本的应用程序吗? 当然,您可以对所有这些版本进行多目标定位,甚至可以插入更多目标定位包。 我将在本周晚些时候发表有关便携式库的博客文章,该库是.NET 4.5中的新版本,可为任何CLR(包括Xbox,Phone,Mono等)创建库。

Screenshot of the multi-targeting dropdown in Visual Studio

为.NET 4和.NET 4.5安全开发 (Developing Safely for both .NET 4 and .NET 4.5)

It's been implied on blogs that if you install .NET 4.5 on your machine that you can't safely develop for .NET 4. In Rick's post, he compares two DLLs on a .NET 4 machine and again after the .NET 4.5 in place upgrade. How can you target safely against .NET 4 if you've installed .NET 4.5? You don't have those .NET 4 DLLs anymore, right?

博客上暗示,如果在计算机上安装.NET 4.5,则无法安全地为.NET 4开发。在Rick的帖子中,他比较了.NET 4计算机上的两个DLL,然后比较了.NET 4.5之后升级。 如果已安装.NET 4.5,如何安全地针对.NET 4? 您不再有那些.NET 4 DLL,对吗?

Actually you do. They are in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework.

其实你知道它们位于C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ .NETFramework中。

Reference Assemblies

Let's prove it on a machine with Visual Studio 11 Beta. I'll make a DLL and reference System.Web and make use of one of the added types in that assembly. Yes, it's a screenshot of code, but hang in there.

让我们在装有Visual Studio 11 Beta的计算机上进行验证。 我将制作一个DLL并引用System.Web,并使用该程序集中添加的类型之一。 是的,它是代码的屏幕截图,但是挂在那里。

Using the .NET 4.5 ModelBinderDictonary Type

Now I'll change the properties of my project from .NET 4.5 to .NET 4. I won't change anything else. I'll build. Note that the type isn't there, I get a build error and I can't reference the namespace. You will know if you're using new .NET 4.5 functionality. The multi-targeting build system was designed for this and existed as far back as .NET 3.5. Those reference assemblies are there to catch this kind of thing.

现在,我将项目的属性从.NET 4.5更改为.NET4。我将不会进行任何其他更改。 我会建立。 请注意,类型不存在,出现构建错误,并且无法引用名称空间。 您知道您是否正在使用新的.NET 4.5功能。 为此,设计了多目标构建系统,该系统可以追溯到.NET 3.5。 这些参考程序集可用来捕获此类事件。

Referencing .NET 4 and using a type we don't have will cause a compiler error

So while .NET 4 and .NET 4.5 don't live side by side on your system at runtime, Visual Studio knows about all the different versions of .NET and the compiler will reference different versions when you build.

因此,尽管.NET 4和.NET 4.5在运行时不会并存于您的系统上,但Visual Studio知道.NET的所有不同版本,并且编译器在构建时会引用不同的版本。

If you are making a client app, like WinForms, Console, WPF, etc, this is all automatic. Your app.config contains that fact that you need .NET 4.5 and you'll even get a prompt to install it.

如果您要制作客户端应用程序(例如WinForms,Console,WPF等),那么这都是自动的。 您的app.config包含您需要.NET 4.5的事实,甚至会提示您安装它。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

So if I run my .NET 4.5 Console App on a .NET 4.0 machine now I get a nice dialog.

因此,如果现在在.NET 4.0机器上运行.NET 4.5控制台应用程序,我会看到一个漂亮的对话框。

A dialog that pops up when running .NET 4.5 apps on .NET 4 to prompt an update

Looks like this technique doesn't work on ASP.NET (I would expect a Yellow Screen of Death)...I will talk to the team about that. I think this is a good thing and ASP.NET should respect it also.

看起来这种技术在ASP.NET上不起作用(我希望死亡的黄屏)...我将与团队讨论此事。 我认为这是一件好事,ASP.NET也应该尊重它。

UPDATE #2: The system will throw an error when an ASP.NET 4.5 application is deployed to an ASP.NET 4 system. The default templates on for ASP.NET 4.5 applications include the targetFramework attribute set to 4.5 like this:

更新#2:ASP.NET 4.5应用程序部署到ASP.NET 4系统时,系统引发错误。 ASP.NET 4.5应用程序的默认模板包括将targetFramework属性设置为4.5,如下所示:

<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
</system.web>
</configuration>

This will throw a YSOD if you deploy a 4.5 to a 4 machine like this: "The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework."

如果将4.5部署到4台计算机上,则将抛出YSOD:“'targetFramework'属性当前引用的版本晚于.NET Framework的已安装版本。”

UPDATE: If you really, really want to detect .NET 4.5 at runtime, don't check versions or build numbers. Check for the existence of the feature you want to use. For example, from this Stackoverflow question by Christian K, here's how to detect .NET 4.5 programmatically.

更新:如果您确实要在运行时检测.NET 4.5,请不要检查版本或内部版本号。 检查是否存在要使用的功能。 例如,根据Christian K提出Stackoverflow问题,以下是如何以编程方式检测.NET 4.5的方法。

However, David from the CLR team (in the comments) says that this is not a good idea. He says to check if an important feature is there and use it. Don't cheat and infer .NET versions.

但是,CLR团队的David(在评论中)说这不是一个好主意。 他说要检查是否有重要功能并使用它。 不要欺骗和推断.NET版本。

"The IsNet45OrHigher example is not what we'd recommend. By feature detection, we mean 'detecting the presence of a feature before you use that feature', <i>not</i> 'using the presence of a feature to determine what version of .NET you are runnning on."

“ IsNet45OrHigher示例不是我们建议的示例。通过特征检测,我们的意思是'在使用该功能之前先检测特征的存在',<i> </ i>'不使用特征的存在来确定什么。您正在运行的.NET版本。”

public static bool IsNet45OrNewer()
{
// Class "ReflectionContext" exists from .NET 4.5 onwards.
return Type.GetType("System.Reflection.ReflectionContext", false) != null;
}

Microsoft has said the same thing about Operating System features:

Microsoft对操作系统功能说了同样的话

Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself.

通常,确定当前操作系统不是确定特定操作系统功能是否存在的最佳方法。 这是因为操作系统可能在可再发行的DLL中添加了新功能。 而不是使用GetVersionEx来确定操作系统平台或版本号,而要测试功能本身的存在。

相关文章 (Related Posts)

Sponsor: My sincere thanks to Axosoft for sponsoring this week's Hanselman.com feed! Imagine agile project management software that is brilliantly easy to use, blazingly fast, totally customizable, and just $7 per user. With OnTime Scrum, you won't have to imagine. Get started free.

赞助商:非常感谢Axosoft赞助了本周的Hanselman.com feed! 想象一下敏捷项目管理软件,它非常易于使用,快速,完全可定制,每位用户只需7美元。 有了OnTime Scrum,您将不必想象。 免费开始。

翻译自: https://www.hanselman.com/blog/net-versioning-and-multitargeting-net-45-is-an-inplace-upgrade-to-net-40

vue 什么是就地复用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值