13

I have installed C# extensions, my .NET framework is updated, I just can't fix it.

enter image description here

3 Answers 3

26

I have found the fix and I hope this will help someone in the future.

  1. Find your .csproj file.
  2. Change LangVersion property to desired version.

enter image description here

<PropertyGroup>
    <LangVersion>7</LangVersion>
</PropertyGroup>
Sign up to request clarification or add additional context in comments.

2 Comments

What if I don't have it?
If you don't have it there, just append it to the <PropertyGroup> section. Try changing the language version value and see the behaviour. It does work.
7

In vs code
Go to the .csproj file and change

         <LangVersion>4.0</LangVersion>

to any version you want eg. <LangVersion>7.2</LangVersion>

In Visual Studio

Right-click on the project node in Solution Explorer and select Properties.

Select the Build tab and select the Advanced button.

In language version dropdown, select any version you want.

enter image description here

2 Comments

Thanks for the comment, but I am not using Visual Studio, I am using Visual Studio Code, those are 2 different things.
I have found the fix and posted the solution.
2

If you want to change it for only one project, you can edit the project's .csproj file (as other answers here show):

<PropertyGroup>
    <LangVersion>7</LangVersion>
</PropertyGroup>

But if you have multiple projects in your solution, and want it changed for all, you need to do the following:

  1. Create a file named: "Directory.Build.props" in the root of the solution.

  2. Add the following to that file:

<Project>
 <PropertyGroup>
   <LangVersion>9.0</LangVersion>
 </PropertyGroup>
</Project>

Official documentation is here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.