Search Unity

Question How to update C# from 9.0 to 11.0?

Discussion in 'Code Editors & IDEs' started by Kujji, Aug 28, 2023.

  1. Kujji

    Kujji

    Joined:
    Oct 20, 2021
    Posts:
    109
    I want to use required here, but i get error that i need c# 11.0
    Code (CSharp):
    1. using Microsoft.Build.Framework;
    2. using System.Collections.Generic;
    3. public class BackendClient
    4. {
    5.     public required string url { get; set; }
    6.     public string appId;
    7.     public string deviceId;
    8.  
    9.     public BackendClient(string url, string appId, string deviceId)
    10.     {
    11.         this.url = url;
    12.         this.appId = appId;
    13.         this.deviceId = deviceId;
    14.     }
    15.  
    16.     public List<Category> getCategories()
    17.     {
    18.  
    19.         return null;
    20.     }
    21. }
    I have Mircrosoft Visual Studio version 17.7.2, .Net Framework version 4.8.09032, but in Assembly-CSharp i have this version of C#
    <PropertyGroup>
    <LangVersion>9.0</LangVersion>
    </PropertyGroup>
    I changed it on this
    <PropertyGroup>
    <LangVersion Condition="'$(MSBuildProjectExtension)'=='.csproj'">preview</LangVersion>
    </PropertyGroup>
    And after previous this
    <LangVersion>preview</LangVersion>
    But after starting the unity project with code or assembly in visual studio it returns to 9.0 version. How can i change version to 11.0?
     
    Last edited: Aug 28, 2023
  2. Kujji

    Kujji

    Joined:
    Oct 20, 2021
    Posts:
    109
    I've tested new lines in assembly, error with 11.0 version c# left after i added <PropertyGroup> <LangVersion>latest</LangVersion> </PropertyGroup>, but now i get error - missing compiler required member 'system.runtime.compilerservices.required member attribute..ctor' on this line - public class BackendClient
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,798
    sailro likes this.