question

NicholasPiazza-0093 avatar image
0 Votes"
NicholasPiazza-0093 asked ·

How enable C# 9.0 Features on Visual Studio 16.8.3?

I currently use Visual Studio 2019 build 16.8.3. I understand that C# 9.0 features should be available on that platform now. However, if I try to declare a 'record' type in Visual Studio, it shows an error. For example:

 namespace Records
 {
     public record Person
     {
            
     }
    
 } // namespace Records

It shows squiggly red lines under 'record' and 'person'. The record error is CS0246: The type or namespace name 'record' could not be found... The Person error is CS0116: A namespace cannot directly contain members such as fields or method and CD0548: '<invalid-global-code>.Person': property or indexer must have at least one accessor.

How do I get Visual Studio to recognize and use C# 9.0 features?

Thanks.


dotnet-csharp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered ·

In the Properties for the project, what setting do you have here?

Build->Advanced->Language version

  • Wayne

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NicholasPiazza-0093 avatar image
0 Votes"
NicholasPiazza-0093 answered ·

It won't let me change the 'Language version'. Says: Automatically selected based on framework version. I edited the .csproj file to change the framework version from 'netcoreapp3.1' to 'netcoreapp5.0' and that fixed the problem. Thanks for the help.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AnandhakrishnanVenkatachalam-1766 avatar image
0 Votes"
AnandhakrishnanVenkatachalam-1766 answered ·

For SDK Style projects <LangVersion> can be set to latest as below in csproj file

 <Project Sdk="Microsoft.NET.Sdk">
    
     <PropertyGroup>
         <TargetFramework>netstandard2.1</TargetFramework>
         <LangVersion>latest</LangVersion>
     </PropertyGroup>
    
 </Project>



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NicholasPiazza-0093 avatar image
0 Votes"
NicholasPiazza-0093 answered ·

Sorry, I solved this problem a few months ago. We can close this question.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.