.NET5发布,这个微软“全家桶”会是.NET的春天吗?

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在全面开源的步伐下,微软也逐步跟上了脚步,作为微软最早迈向开源的重要软件之一,.NET 5的发布对微软及其使用者都具有重要意义。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微软未来目标是将所有的 .NET 组件整合到一个产品下,然后用户可以根据需求使用 .NET 的某个部分,而不是单独下载或安装所有内容。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"对于Visual Studio用户,需要Visual Studio 16.8或更高的版本才能在Windows上使用.NET 5.0,在MacOS上使用最新版本的Visual Studio for Mac)。Visual Studio Code的C#扩展也已经支持.NET5.0和C#9。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"NET 5.0是.NET统一之旅的第一个版本。微软希望 .NET Framework 开发者能够迁移他们的代码和应用到 .NET 5.0 上,为明年发布的 .NET 6.0 将 Xamarin 开发者过渡到统一平台奠定基础。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"版本发布时间轴:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/26/262e73f5b4884ac289066657e54df64c.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET Core 3.0 已于2019/09推出","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET Core 3.1 已于 2019/12推出,为 LTS (Long Term Support,长期支援版),之后.NET Core 将更名.NET,固定每年释出新版,并定义双数版号为LTS版,单数版号为Current版。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET 5.0 2020/11","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET 6.0 LTS 2021/11","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET 7.0 2022/11","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET 8.0 LTS 2023/11","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如有兴趣,可以体验一下,历来发布资料及地址:https://dotnet.microsoft.com/download/dotnet/5.0","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/56/56bac10b45c8c571256829f2a62cb47b.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/da/dae3415522546f285ec7c0de5e48bd45.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET 5.0是.NET Framework和.NET Core核心的结合,旨在统一.NET平台。.NET 5.0毫无疑问代表的是.NET的未来,但是目前国内大部分企业使用的依然是.NET Framework,不过长期来看,升级似乎不可避免。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6b/6ba2d6f86b88c95780a298e8fc92a187.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了充分论证.NET5的性能,自首个预览版发布以来微软已经进行了广泛的内部部署,除了在 .NET 5.0 上运行.NET网站外,Bing也在使用这个新平台。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"并在此次更新中强调了一些比较显著的变化,包括一些性能上的改进。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"以下是微软发布的此版本的相关亮点:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1..NET 5.0 已经部署到 http://dot.net和 http://Bing.com 托管数月,已经得到了实战检验。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.很多组件的性能都得到了极大的提高。.NET 5.0 中 ARM64 的性能 和 GRPC 等都有改善","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.C# 9和F# 5提供了新的语言改进,如C# 9的顶层程序和记录,而F# 5则提供了交互式编程和.NET上功能编程的性能提升。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4..NET库对Json序列化、正则表达式和HTTP(HTTP 1.1、HTTP/2)的性能有所提升。它们现在也被完全注释为可空性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"5.由于GC、分层编译等方面的完善,P95延迟有所下降。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"6.应用部署选项更好了,有了ClickOnce客户端应用发布、单文件应用、容器镜像尺寸减小,并增加了Server Core容器镜像。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"7.平台范围扩大,增加了WindowsArm64和WebAssembly。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"8.一个值得注意的变化是,.NET 5.0应用可以原生运行在ARM64 Windows设备上,消除了仿真带来的一些性能障碍。然而,在这个版本中,Windows 桌面组件并不能用于ARM64设备--这计划在.NET 5.0的服务更新中进行。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"近几年.NET Core 的开源项目也非常活跃,随着.net5的发布,这些项目将会逐步整合到.net5及之后的版本中。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"但是有几点需要特别注意:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前的.NET5虽然已经足够强,但严格来说依然属于实现阶段,.NET6.0或许更值得期待。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前关于.net5的挺多升级并未在实际中讨论,例如正则性能提升,静态正则缓存;Kestrel 的通信性能提升,支持Http3; 证书互转,增强 SSL 通信;readonly struct 在内部的应用;HttpClient 人性化的 Api,支持 webassembly, 支持序列化结果,支持 Quic 等;Json 支持字段序列化,只读类型序列化,Web类型序列化,循环引用序列化等特性;GC 可分配 no zero 的内存空间,分配“固定住”的大堆空间,GCMemoryInfo 等等。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果并没有急切的需求,目前并不建议升级至5.0,可以将5.0作为研究跳板,在明年微软发布6.0LTS长期维护版本的时候再考虑升级,降低风险。当然,这个需要根据实际情况进行评估。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"......","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"接下来","attrs":{}},{"type":"text","text":",放一个.NET Core3.1升级.NET5可能遇到的坑,以作参考,不需要的可以略过此部分,作者“dotnet跨平台”。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/55/55c7dfb0dbc8ec75cbb6965f58ef43c8.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此前Scott Hunter在博客信誓旦旦.NET Core3.1平滑迁移.NET5,于是当天就去升级我的宝藏项目,结果是大坑没有,小坑不断,折腾了一天时间才搞定,下面来仔细捋一捋,给搭建提供点参考。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"背景介绍","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"升级的项目是之前开源在Github上,也曾一周新增300star,后面虽因故关闭了,但我个人是非常用心的。这不.NET5刚发布,第一时间就开始了升级。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"项目是个微信小程序商城,后端是微服务架构支撑的,Ocelot网关+Consul服务注册发现+Core WebApi+gRPC+IdentityServer4都安排上了,整体还是比较复杂的,MongoDB、Redis、RabbitMQ也都安排上了,然后就在.NET Core3.1升级.NET5的过程中,各种踩坑。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/9c/9cd8a3b7eb17a45d454807c853841087.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"VS升级坑","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"升级的第一个坑来自于VS工具升级!之前.NET5预览版、RC1、RC2都是用的Visual Studio 2019 Preview,这会儿.NET5正式版发现只需要把Visual Studio 2019升级到V16.8即可,然后就兴冲冲的升级去了,结果当头一棒:Visual Studio Installer提示网络未连接无法下载!当然不是我的网络问题,其实是DNS解析上出了毛病(部分用户会遇到,解决办法是把电脑的DNS设置为8.8.8.8即可),但毕竟当时是11号凌晨,以为是微软官方同步不够,我就选择换工具,直接去Linux下用VS Code升级了,然后就开始了第二波环境坑!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"经验:如果遇到Visual Studio Installer提示网络未连接无法下载,可以将当前电脑DNS设置为8.8.8.8即可","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Linux环境坑","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Linux环境下VS Code开发之前都蛮熟悉了,这次想着是升级.NET5,就顺手把Linux系统从CentOS7给换成了CentOS8,然后又华丽丽的各种坑。比如CentOS8中网卡名字从ens33变成了eth0,用nftables替代iptables,各种小变化让人防不胜防,然后docker最新版本的命令也跟之前有些小变化,导致之前整理的Linux+Docker操作笔记各种失灵,来来回回折腾了好几个小时。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"当然,环境只是环境,折腾完就过去了,而代码迁移层面的坑才是最麻烦的,因为并不知道还有多少没发现!","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/44/44211784467550d336ebb4f4eaef1f17.png","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":".NET5迁移坑坑坑","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"项目从.NET Core3.1升级到.NET5非常easy,在 global.json 中将SDK版本从3.1升级成5.0,再将TargetFramework从netcoreapp3.1换成net5.0即可。还有部分类库命名空间变化完全没关系,宇宙第一IDE的智能提示轻松解决。但是,在真实项目迁移过程中,我却遇到了各种小问题:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1.Core WebApi框架模板项目中默认集成了swagger,这个是新增的,但之前项目有一些自定义配置和扩展,也导致了冲突。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.IdentityServer4第三方框架版本升级,API变化很有点多,改动不了不少代码,这个锅虽然不是.NET5的,但也是升级项目会遇到的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.尝试C#9花了一些时间,想体验下新语法新特性,如Native ints原生Ints、Pattern matching improvements模式匹配改进版,结果几次把自己绕进去了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4.项目升级完发现的Bug,DateTime这个天天见的值出现了变化,在 ASP.NET Core 3.1 及更早版本中,DateTime绑定的是服务器本地时间,而5.0之后,DateTime绑定的是UTCTime。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"http://www.learun.cn/","title":null},"content":[{"type":"text","text":"Learun","attrs":{}}]},{"type":"text","text":".net","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章