Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
590 views
in Technique[技术] by (71.8m points)

.net 5 - How to enable C# 9.0-preview

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As of October 2020:

Please see @Pac0's answer here: https://stackoverflow.com/a/64386529/159145

As of June 2020:

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

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).

So your *.csproj file should look like this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...