How enable C# 9.0 Features on Visual Studio 16.8.3?

Nicholas Piazza 531 Reputation points
2020-12-20T22:09:36.387+00:00

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.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
0 comments No comments
{count} votes

3 additional answers

Sort by: Most helpful
  1. Nicholas Piazza 531 Reputation points
    2020-12-20T22:55:34.48+00:00

    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.

    0 comments No comments

  2. Anandhakrishnan Venkatachalam 1 Reputation point
    2021-03-11T07:11:48.71+00:00

    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>
    

  3. Nicholas Piazza 531 Reputation points
    2021-03-11T12:39:10.343+00:00

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

    0 comments No comments