NET 9 officially released

NET 9 officially released

NET 9 is officially released! This is the most productive, modern, secure, intelligent and powerful release of. NET to date.

最后更新 11/13/2024 2:47 AM
.NET Team
预计阅读 26 分钟
分类
.NET
标签
.NET C# security .NET 9 officially released

This article is translated with the help of AI and verified by the webmaster.

Today, we are excited to announce that. NET 9 has been officially released! This is the most productive, modern, secure, intelligent and powerful release of. NET to date. It embodies another year of work by thousands of developers around the world, and this new release includes thousands of performance, security and functional improvements. You will find that from programming languages, development tools to workloads, the entire. NET technology stack has been enhanced in all aspects, allowing you to develop based on a unified platform and easily inject artificial intelligence elements into your applications.

点击查看带有工作负载、工具、生态系统和操作系统的.NET概览

Download resources for. NET 9, as well as updates for Visual Studio 2022 and the C#Development Kit for Visual Studio Code, are now publicly available.

🔽 下载.NET 9

获取Visual Studio 2022 v17.12版本

.NET团队、合作伙伴以及.NET社区将在.NET Conf 2024(为期三天的免费线上开发者活动,举办时间为11月12日至14日)上展示.NET 9的新特性,并深入剖析各项功能。快来加入我们吧!

Let's take a look at the highlights of. NET in terms of development languages, workloads, and tools.

Unparalleled performance-apps run faster and consume less memory

.NET 9是.NET至今性能最强的版本,运行时、工作负载以及语言层面共有超过1000项与性能相关的变更,其采用的更高效算法能够生成更优质的代码。斯蒂芬·图布(Stephen Toub)对.NET 9性能改进内容进行了深入剖析,那是一篇必读文章,不过在此我们还是先来讨论一下该版本中的部分亮点。

The server garbage collection (Server GC) mechanism has been significantly adjusted to adapt based on the memory requirements of the application, rather than the resources (memory and CPU) available in the environment (machines, virtual machines, or containers). This adjustment method has far-reaching implications in multi-core environments, especially when application memory is small or changes significantly over time. Previously, the implementation of workstation and server garbage collection mechanisms would produce very different results, and users needed to weigh between the two. This adjustment should be attractive to those who use workstation garbage collection mechanisms to control cloud application memory usage. Memory optimizations may impose a certain throughput cost, but this cost may not be obvious. The server garbage collection mechanism can be configured to use legacy implementations, which may come in handy during testing.

The TechEmpower benchmark also dwarfs. NET 9, which achieved higher throughput while significantly reducing memory usage. The decline in memory usage is due to changes in the server garbage collection mechanism.

图表展示每秒请求数(RPS)提高15%,内存使用量降低93%

运行时重新引入了向量化,增加了对新芯片架构的支持,涵盖了Arm64可伸缩向量扩展(SVE)、英特尔高级矢量扩展10(AVX10),并对运行时进行了硬件加速。RyuJIT提升了Arm64循环基于配置文件引导的优化(PGO)以及边界检查等方面的性能。得益于采用了原生提前编译(Native AOT)所使用的异常模型,异常处理速度提升了50%。

动态的基于配置文件引导的优化(PGO)已更新,能够对更多代码模式进行优化。现在,即时编译器(JIT)会为应用中常见以及未曾出现过的类型转换生成快速路径代码。像(IFoo)myFoomyFoo is IFoo这类类型转换在C#中极为常见。此外,对于所观察到的常见缓冲区长度,它还能够展开并向量化对缓冲区执行的部分操作。尽管这一变更需要禁用“ReadyToRun”功能,但能使执行速度提高70%。

LINQ在多种常见场景下也进行了优化。当基础数组、集合或者可枚举对象为空时,诸如TakeDefaultIfEmpty这类方法的返回速度如今可提升多达10倍。Enumerable.SequenceEqual方法已经针对数组输入进行了特殊处理,它会将操作委托给MemoryExtensions.SequenceEquals方法,通过将数组作为 spans 传递,实现高效迭代和向量化操作。现在,List<T>也具备了这一能力。

System.Text.Json的底层细节得到了显著优化,各项操作的性能提升幅度超过50%。JsonProperty.WriteTo方法现在能够直接写入UTF8字节,从而避免了字符串分配操作。新的JsonMarshal.GetRawUtf8Value应用程序编程接口(API)会返回UTF8字节,作为JsonElement.GetRawText(返回字符串且需要编码和分配内存)的替代方案。如果能从给定的可枚举对象中获取元素数量,JsonObject现在可以正确设定其底层支持存储的大小,从而避免分配内存以及调整大小所产生的成本。

In addition to these fundamental improvements to. NET, you will find performance improvements for all types of applications, so read on to learn more.

NET Aspire-the basic component for building better applications

.NET Aspire是一组功能强大的工具、模板以及软件包,旨在助力无缝开发可观测且可用于生产环境的应用程序。距离.NET Aspire首次发布仅仅过去了六个月,我们已经对整个技术栈的各个部分进行了改进,从遥测和指标仪表板中的新特性,到云应用更精简的部署流程,都有涉及。看到各类应用纷纷采用.NET Aspire,以及社区根据自身场景接纳相关集成与工具,着实令人欣喜。此外,我们看到微软内部也有大量应用采用了这一技术,例如Xbox团队和Copilot团队都已将.NET Aspire集成到现有服务中,借助易于获取的洞察信息以及各种兼容的Azure集成,进一步优化了内部开发流程。

.NET Aspire概览

此次发布的.NET Aspire 9带来了一些大家呼声很高的功能,可助力简化应用开发流程。现在,你能够通过仪表板启动和停止资源,在调试会话之间保持容器处于运行状态,还可以访问包括WaitFor在内的新API,以便更好地管理资源启动过程。我们与社区紧密合作,为OpenAI、Ollama、Milvus等众多平台推出了全新的无缝集成功能。我们简化了获取.NET Aspire的流程,使其更易于融入应用当中,同时改进了与Azure容器应用相关的部署场景,并且很高兴地宣布,现已为Azure函数提供.NET Aspire预览版支持。

.NET Aspire 9新特性概览

.NET Aspire还有诸多内容等待你去探索,涵盖了从工具到更广泛的生态系统,比如全新的.NET Aspire社区工具包。如果你打算开始使用.NET Aspire,不妨看看我们在微软学习平台(Microsoft Learn)上提供的免费课程以及新的.NET Aspire认证,它们将助力你开启.NET Aspire之旅。当然,也请让我们知晓你对.NET Aspire的看法,你可以通过GitHub.NET Discord或者我们的直播流反馈给我们。

Artificial intelligence-a booming artificial intelligence ecosystem

We continue to expand. NET's capabilities in building and injecting artificial intelligence into applications. Now with new learning materials and examples, integration with the ecosystem is simpler, working with partners to create a vibrant artificial intelligence community, and deploying artificial intelligence solutions to the cloud has become smoother than ever before. Many companies in all industries have adopted. NET to create first-class artificial intelligence experiences for their customers, including H&R Block, Blip, and KPMG. Your favorite coding assistant, GitHub Copilot, is powered by. NET, and the new Microsoft Copilot experience is also built completely based on. NET.

When developing artificial intelligence services and applications, it is crucial for developers to be able to keep up to date with the latest developments. Because of this, we have worked together with partners in many artificial intelligence ecosystems such as Azure, OpenAI, LlamaIndex, Qdrant, Pinecone, Milvus, AutoGen, OlamaSharp, and ONNX Runtime to provide. NET developers with a series of powerful feature options.

展示.NET人工智能生态系统中各类库和组件的概览图

We are also making it easier to integrate AI-integrated controls into. NET applications by working with the community and control vendor partners to build an intelligent component ecosystem.

Artificial intelligence building modules for. NET

一个强大的生态系统意味着开发者在选择最适合自身场景的方案时,拥有了比以往更多的选择。我们思考了如何简化这些集成流程,并消除因生态系统中应用程序编程接口(API)和功能数量不断增长所带来的准入障碍。为此,我们与语义内核(Semantic Kernel)展开合作,在Microsoft.Extensions.AIMicrosoft.Extensions.VectorData项目下,为.NET生态系统引入了一组抽象概念,它们为与人工智能服务(例如小型和大型语言模型、嵌入向量、向量存储以及中间件)进行交互提供了统一的C#抽象层。这种简化后的新方法已经在早期采用者(如PiecesOllamaSharp)那里取得了良好的成效。

解释人工智能扩展工作原理的示意图

Tensors and Tokenizers

Microsoft.Extensions.AI和VectorData只是我们在.NET 9中所提供构建模块的一部分,我们还对相关库和基础数据类型进行了重大改进,以推动人工智能开发。Microsoft.ML.Tokenizers针对包括GPT(4、o1等)、Llama、Phi以及Bert在内的热门模型系列,在分词器方面进行了改进,此外还新增了对字节级字节对编码(Byte-Level BPE)、SentencePiece以及WordPiece等分词算法的支持。

随着语言模型即服务的出现,开发者使用人工智能的门槛大幅降低。Tensor<T>也为人工智能开发带来了助力,它作为一种新的数据类型,可用于表示多维数据,从而简化了库之间的交互操作以及相关运算的应用。

We can't wait to see what you can achieve with these new building block integration capabilities. If you want to get started quickly, you can browse the artificial intelligence documentation and sample code we provide for. NET.

GitHub Copilot enhancements for. NET developers

GitHub Copilot通过在编辑器体验方面提供更优质的结果,并在.NET开发者的常规工作流程中提供人工智能辅助,从而提升了开发效率。随着Visual Studio和Visual Studio Code的最新版本发布以及GitHub Copilot的更新,这一体验变得更加出色。开启Copilot后,集成开发环境(IDE)中处处融入了人工智能,可在开发者生命周期的各个环节(从编写代码、编写测试到调试应用)为你提供帮助。以下是在最新版本中你可以期待的部分功能:

  • ** Artificial intelligence variable inspection **: Optimize the debugging workflow by integrating artificial intelligence variable inspection functions.
  • ** AI-driven Enumerable Object Visualization Tool **: Provide AI-driven editable Language Integrated Query (LINQ) expressions in the Enumerable Object Visualization Tool.
  • ** Repair code with GitHub Copilot **: GitHub Copilot can help you solve code problems.
  • ** Better artificial intelligence completion function for C#*: GitHub Copilot will introduce more context information from relevant source files to improve the completion effect of C#code.
  • ** Debugging and testing with GitHub Copilot **: Get help with debugging failed tests by using the "Debugging and Testing with GitHub Copilot" function.

Full-stack Web development using ASP.NET Core and Blazor

ASP.NET Core是我们用于.NET的全栈式Web框架,提供了构建现代化Web应用以及可扩展后端服务所需的一切功能。.NET增添了众多新特性,在性能、可访问性以及安全性方面均有显著改进。使用.NET 9构建的ASP.NET Core应用默认具备安全性,对提前编译(AOT)的支持得到了扩展,监控和跟踪功能也有所改善,再加上内置的性能提升,应用将实现更高的吞吐量、更快的启动时间,并且内存使用量更低。

.NET 9中的ASP.NET Core——质量、开发体验、云原生特性

Optimization of static files in ASP.NET Core

Static Web resources, such as JavaScript and CSS files, are an integral part of almost every Web application. ASP.NET Core in NET 9 now optimizes these files during the build and release process for efficient deployment. During the build phase, ASP.NET Core recognizes all static Web resources and generates a fingerprinted version of the file by adding a content-based hash to the file name. This fingerprinting mechanism ensures the uniqueness of file names, avoids the use of older versions of files, and allows files to be actively cached. When the application is released, these files are also pre-compressed using the Brotli algorithm, which greatly reduces the file download size and reduces the compression workload on the server. These files are processed via endpoint routing at runtime, which means you can now use other end-aware features for static files, such as per-endpoint authorization.

Improvements to Blazor in. NET 9

In. NET 9, Blazor is more powerful than ever, helping you build beautiful modern Web and hybrid applications. This release brings performance improvements to all aspects of Blazor, adding Blazor hybrid applications and Web application templates, and providing developers with new application programming interfaces (APIs) to create a satisfying user experience.

Blazor现在能够在运行时通过新的RendererInfo应用程序编程接口(API)检测组件的渲染模式,并相应地调整组件渲染方式。在预渲染期间,你可以禁用或隐藏交互元素,待组件具备交互性后再启用它们。

The example code is as follows:

@if (RendererInfo.IsInteractive)
{
    <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
}
else
{
    <p>One moment, please</p>
}

Blazor apps that use interactive server-side rendering (Blazor Server) will benefit from a new reconnect experience with a more user-friendly interface, faster reconnecting to the server, and automatically handling page reload operations when a user's connection is lost.

Enhancements to OpenAPI in ASP.NET Core

全球范围内,众多大规模服务都是基于使用ASP.NET Core构建的应用程序编程接口(API),并且我们在每一次发布时都会持续改进构建这些API的体验。对于API开发者来说,.NET 9中的一大亮点是通过Microsoft.AspNetCore.OpenAPI软件包新增了对OpenAPI文档生成的内置支持。元数据会自动从应用代码、属性以及扩展方法中提取出来。之后,还可以使用针对操作、模式或者整个文档进行操作的转换器,对文档做进一步定制。在最小化API应用中,该功能对原生提前编译(Native AOT)友好,使你能够针对最佳性能对应用进行优化。除此之外,OpenAPI文档可以在构建时生成,并集成到利用OpenAPI工具的本地开发工作流程以及构建管道当中。

展示新的API、文档以及测试情况的示意图

Security improvements in ASP.NET Core

Security remains a core focus of ASP.NET Core, and you will find several improvements that help ensure your application is secure by default. It is now easier to set up trusted development certificates on Linux systems, making it easier to enable Hypertext Transfer Security Protocol (HTTPS) during development. Blazor now has a built-in application programming interface (API) for passing authentication status to clients, also supports adding additional parameters to OAuth and Open ID Connectivity (OIDC) authorization requests, and provides support for Push Authorization Requests (PARs). Finally, we have strengthened ASP.NET Core's data protection capabilities and improved Kestrel's connection metrics to make it easier to detect the cause of connection failures.

.NET 9中ASP.NET Core新特性概览

NET MAUI-Enhance multi-platform application development

.NET MAUI是使用.NET跨移动端和桌面端构建多平台应用的绝佳方式。它除了提供统一的抽象层,能通过单一应用程序编程接口(API)访问原生功能,并基于单一代码库创建出色的跨平台用户界面外,还包含了基于.NET访问原生API来构建适用于安卓(Android)、苹果iOS、苹果macOS以及Windows系统应用的基础功能。进入.NET 9阶段,.NET MAUI的首要目标就是提升质量和可靠性,以便你能更轻松地将应用投入生产环境。过去一年里,我们看到在谷歌应用商店(Google Play Store)中,使用.NET MAUI构建的应用数量增加了一倍多,开发者的使用率增长超过30%,达到历史最高水平,而且社区的参与度和贡献也十分惊人。

展示.NET MAUI使用量和拉取请求(PRs)增长情况的图片

最近,我们欢迎Syncfusion(.NET生态系统中领先的组件供应商)为.NET MAUI做出贡献。自今年7月至9月,Syncfusion开始为.NET MAUI贡献代码以来,其贡献量占社区总贡献量的比例超过了55%,与前三个月相比,增长了557%,这得益于其原本就非常出色的贡献成果。在.NET 9中,我们将社区放在核心位置,引入了一个全新的项目模板,其中包含14个免费且开源的Syncfusion控件以及来自社区的其他热门库,展示了针对模型 - 视图 - 视图模型(MVVM)、数据库访问、导航、视图刷新以及其他常见应用模式的推荐实践方法。你可以利用这个模板快速开启应用开发之旅。

展示使用.NET MAUI开发的移动端和桌面端应用示例的图片

我们一直倾听开发者的心声,.NET 9为桌面端和移动端应用带来了性能提升、可靠性增强以及更深入的集成功能。你会发现.NET MAUI在各方面都有显著的性能改进,包括针对iOS和Mac Catalyst系统的CollectionView(集合视图)与CarouselView(轮播视图)的全新实现,对现有控件和应用生命周期的更新,以及原生提前编译(Native AOT)和剪裁功能的增强,这些都有助于你构建体积更小、运行速度更快的应用。除了支持最新的iOS、macOS和安卓操作系统外,我们在.NET 9中还新增了多项原生平台功能,例如安卓资源包(Android Asset Packs)、与原生库交互的改进,以及通过新的Xcode Sync dotnet工具实现Xcode与Visual Studio Code之间更流畅的集成。

.NET 9中.NET MAUI特性概览

.NET 9中的.NET MAUI有诸多值得喜爱和探索的内容。一定要仔细查看新特性文档,并尝试使用新的项目模板哦。

Windows development using. NET 9

借助.NET 9,你的Windows应用将能够使用最新的操作系统特性和功能,同时确保它们比以往任何时候都更具性能且更易于访问。无论你是使用WinUI 3Windows应用软件开发工具包(Windows App SDK)来开发新的现代化应用,还是对现有的Windows Presentation Foundation(WPF)以及Windows Forms应用进行现代化改造,你的Windows应用在.NET 9上都能实现最佳运行效果。我们一直与Windows开发者社区紧密合作,带来了大家一直期待的功能。这其中包括为WinUI 3提供原生提前编译(Native AOT)支持,以打造体积更小且性能更优的应用;为WPF引入流畅用户界面(Fluent UI)相关的现代化主题增强功能;为WinForms增添了暗黑模式、现代化图标应用程序编程接口(API),并通过Control.InvokeAsync改进了异步API访问功能。

.NET 9中Windows开发者特性概览

在.NET 9中针对Windows开发还有很多内容值得探索,所以一定要仔细阅读WinUI 3WPF以及WinForms的新特性文档。

C#and F#-your favorite programming languages become better

C#是全球最受欢迎的编程语言之一。在C# 13版本中,我们着重关注了一些特性,它们能让你以熟悉且喜爱的编程风格更轻松、更安全、更快速地编写代码。在方法签名中使用params修饰符的功能在C# 13中通过新增的集合表达式得到了增强。这意味着你不再局限于将params与数组类型搭配使用,而是可以使用任何受支持的集合类型了。

C# 13通过引入使用ref struct值的新方式解锁了更多高性能代码,并且借助System.Threading.Lock让处理多线程应用变得更加容易。

The example code is as follows:

Lock myLock = new();

void Concat<T>(params List<T> items)
{
    lock (myLock)
        Console.WriteLine(string.Join("\e[1mItem: \e[0m", items));
}

F#一如既往地为.NET开发者提供优质的函数式编程体验。F# 9带来了各种语言、库以及工具方面的增强功能,旨在让你的程序更安全、更具弹性且性能更佳。可空引用类型为与C#库的交互带来了类型安全性,优化后的整数范围加速了循环和其他推导式的执行速度,优化后的相等性检查避免了装箱操作,并提升了许多常见操作的性能。区分联合类型会自动生成.Is*属性,便于快速进行情况测试。标准库现在包含了针对集合的随机函数,这在数据科学和游戏开发中非常实用。开发者的工作效率也因诊断功能、解析器恢复以及各种工具改进而得到了提升。

The example code is as follows:

// FS3261: 空值警告:类型'string' 和'string | null' 的可空性不一致。
let methodArgument (s: string | null) = File.Create s
let matchNullableString(s: string | null) =    
        match s with  // `s` 是 string | null 类型
        | null -> 0
        | notNull -> notNull.Length // `notNull` 是 string 类型

还有很多精彩特性等着你去发现,所以一定要浏览C# 13新特性文档以及F# 9新特性文档哦。如果你刚开始踏上C#开发之旅,不妨查看一下与freeCodeCamp合作推出的基础C#认证

The world's top developer tools

伴随.NET 9的发布,我们的开发者工具也进行了更新,这将使你的开发效率达到前所未有的高度。首先,Visual Studio 2022 17.12版本的发布为开发者工作流程的各个方面都带来了一系列效率提升,包括显著的性能增强、更出色的调试与诊断体验、与.NET Aspire更紧密的集成、更深入的云集成、对C# 13的分析器支持、增强的Git支持等等!实际上,此次Visual Studio 2022版本所包含的用户期待功能比以往任何时候都要多。这个版本中总有适合你的功能,相信你一定会喜欢它的。

适用于Visual Studio Code的C#开发工具包也在持续演进,编辑可靠性得到了提高,NuGet包管理功能有所增强,测试适配器和代码覆盖率结果更优,对.NET MAUI开发的支持也得到了改进,项目启动/调试配置也进行了升级。立即下载最新版本的Visual Studio 2022适用于Visual Studio Code的C#开发工具包,让你的开发工作流程从中受益并得到改进吧。

我们知道开发者喜爱命令行界面(CLI),因此我们一直在努力改善.NET CLI的使用体验,并助力其成为安全开发方法的一部分。在.NET 9中,我们对终端日志记录器进行了全面改进,包括添加可点击链接、时长计时器、颜色编码等等。日志记录器的输出更加简洁,而且现在在构建结束时你会看到失败和警告总数的汇总信息,使其比以往更具实用性。dotnet restore命令也已更新,能够审核顶级和传递依赖项是否存在软件包漏洞。这一功能与集中式软件包管理配合默契,使你能够快速将软件包升级部署到代码仓库内的所有项目中。dotnet restore会在终端、Visual Studio以及持续集成/持续交付(CI/CD)管道中基于GitHub安全公告数据库中的软件包漏洞信息向你发出提醒。

展示.NET CLI新特性亮点的图片

.NET软件开发工具包(SDK)中还有很多你会喜欢的内容,所以一定要仔细阅读新特性文档哦。

A thriving community of creators and contributors

我们热爱出色的.NET社区,没有你们的支持和贡献,就不会有.NET 9的诞生。我们收到了来自9000多名社区成员的超过26000次贡献!感谢你们提出的每一个问题、每一条评论、每一次代码审查以及每一个拉取请求,正是你们的付出,才让这个版本成为.NET迄今为止最优秀的版本。我们也很欣慰看到大家对.NET的喜爱,在今年的Stack Overflow开发者调查中,.NET与ASP.NET Core一同被评为最受推崇的框架,C#也被列为顶尖的Web框架和编程语言之一。感谢你们助力构建了这个令人惊叹的全球开发者社区。

带有感谢字样且背景有头像的图片

感谢所有帮助.NET生态系统蓬勃发展的库创建者,是你们让NuGet成为了每年增长速度最快的软件包生态系统。如今,.NET开发者可以使用的软件包已超过42万个,它们的下载次数总计超过5700亿次,这一数字令人惊叹。我们正在大力投入,不断完善NuGet,添加开发者喜爱的功能,并努力使其成为全球最安全的软件包生态系统。

NuGet生态系统概览

NuGet为整个生态系统中的库创建者和使用者都带来了重大改进。NuGet.org网站焕然一新,现在支持暗黑模式,还与GitHub合作,为Dependabot添加了原生NuGet支持,支持通过开源安全基金会(OpenSSF)实现开源计分卡和固定依赖项功能,并增强了与deps.dev的集成,以便更深入地了解项目中的依赖关系。

Start your development journey with. NET 9 now

现在就加入我们在.NET Conf的线上直播活动吧,聆听.NET团队成员现场讲解最新的增强功能。

Download resources for. NET 9 and updates to Visual Studio 2022 and the C#Development Kit for Visual Studio Code are now available.

🔽 下载.NET 9

获取Visual Studio 2022 v17.12版本

For an in-depth understanding of the new features in each part of this release, check out the latest documentation for each part of. NET 9:

In addition, in the next few months, we will publish in-depth profiling blog posts on new features in. NET 9 covering languages, workloads, and tools, so be sure to subscribe to the. NET blog so that you will be notified in a timely manner when new articles are published.

We can't wait to see what you can develop with. NET 9.

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 4/22/2026

Support for. NET by operating system versions (250707 update)

Use virtual machines and test machines to test the support of each version of the operating system for. NET. After installing the operating system, it is passed by measuring the corresponding running time of the installation and being able to run the Stardust Agent.

继续阅读
同分类 / 同标签 2/7/2026

Summary of experience in using AOT

From the very beginning of project creation, you should develop a good habit of conducting AOT release testing in a timely manner whenever new features are added or newer syntax is used.

继续阅读