How to enable C# 9.0-preview

本秂侑毒 提交于 2020-07-30 04:43:07

问题


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?


回答1:


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>



回答2:


Firstly Download .NET 5 and then install Visual Studio Preview Edition. You will now have access to the latest features of C# 9. Also make sure that you project file includes the following.

 <PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>


来源:https://stackoverflow.com/questions/62398572/how-to-enable-c-sharp-9-0-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!