12

I have to update the C# version. Now, I use version 7.3 but I need to use 8 or greater version.

While applying the steps in this link, I faced with the problem as it can be seen in the image.

enter image description here

How can I solve this problem? Is there any way to make it manual instead of automatic?

9
  • 4
    So what happened when you clicked on the link immediately below the disabled control that purports to tell you why you cannot change the version? Commented Aug 11, 2021 at 10:26
  • From the docs, "C# 8.0 is supported on .NET Core 3.x and .NET Standard 2.1." Commented Aug 11, 2021 at 10:30
  • 2
    It's entirely possible to specify it in the project file though - at least with SDK-style projects. Just use <LangVersion>8.0</LangVersion>. Commented Aug 11, 2021 at 10:31
  • I have not find a clear answer from the link Commented Aug 11, 2021 at 10:38
  • 1
    @Gserg Yes, exactly: "The latest C# compiler determines a default language version based on your project's target framework or frameworks." It's nice of it to try to automatically determine a langauge version based on my project's target framework. But the question was: how to change it. An alternate question would be "Why can't I select a different C# version?" Because...i can select a different C# version - so why can't i change it...there - on that screen. Commented Jun 10, 2023 at 16:06

1 Answer 1

7

If you edit your .csproj add this line inside the first <PropertyGroup>

<LangVersion>latest</LangVersion>

or if you want to specify the version

<LangVersion>8.0</LangVersion>

In other words:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{68EAC5EC-1EE6-4B41-BCF8-ED62CA1B6364}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>SqlServerCLRFunctions</RootNamespace>
    <AssemblyName>SqlServerCLRFunctions</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
    <LangVersion>8.0</LangVersion> <!-- added, default is C# 7.3 -->
  </PropertyGroup>
Sign up to request clarification or add additional context in comments.

1 Comment

You might add, to test this put #error version anywhere in the code and it'll give the version for the current project.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.