如何启用 C# 9.0-preview [英] How to enable C# 9.0-preview
问题描述
我已经下载并安装了 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
?
推荐答案
截至 2020 年 10 月:
请在此处查看@Pac0 的回答:https://stackoverflow.com/a/64386529/159145
根据文档中的这个页面 您需要编辑您的 *.csproj
以将
设置为 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 版本,这与以前甚至可以将 C# 7 与 .NET Framework 2.0 前提是您重新实现了自己缺少的 BCL 类型,例如 ValueTuple
和 ExtensionAttribute
).
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-preview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!