如何启用C#9.0预览 [英] How to enable C# 9.0-preview

查看:460
本文介绍了如何启用C#9.0预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载并安装了v5.0.0-preview.5.我的项目定位到net5.0,但是C# 9.0无法正常工作.如何启用C# 9.0?

I have downloaded and installed v5.0.0-preview.5. My project is targeting net5.0 but C# 9.0 is not working. How can I enable C# 9.0?

推荐答案

根据文档中的此页面,您需要编辑*.csproj以将<LangVersion>设置为preview.

According to this page in the documentation you need to edit your *.csproj to set the <LangVersion> to preview.

在有关预览版本的博客文章中也提到过,但没有在上面的文档页面上提到,您还需要将项目的targetFramework属性也更新为net5.0 (这是因为C#设计团队决定将整个C#语言版本限制为最低的BCL版本,这与以前您甚至可以在甚至.NET Framework 2.0中使用C#7的情况不同.

Also mentioned in the blog-post about the preview-release, but not the above documentation page, is that you need to update your project's targetFramework property too to net5.0 (this is because the C# design team decided to restrict entire C# language versions to minimum BCL versions, unlike previously where you could use C# 7 with even .NET Framework 2.0 provided you reimplemented your own missing BCL types like ValueTuple and ExtensionAttribute).

因此,您的*.csproj文件应如下所示:

So your *.csproj file should look like this:

<Project>
 <PropertyGroup>
   <LangVersion>preview</LangVersion>
   <TargetFramework>net5.0</TargetFramework>
 </PropertyGroup>
</Project>

这篇关于如何启用C#9.0预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆