Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to set Editor Assemblies Compatibility Level in 2022 and below?

Discussion in 'Scripting' started by TheSleepyKoala, Apr 6, 2023.

  1. TheSleepyKoala

    TheSleepyKoala

    Joined:
    Aug 24, 2018
    Posts:
    23
    To my knowledge, this option was added in 2023.1 to the Configuration section within Project Settings.

    Is it possible to mimic this in previous Unity versions using code easily, or has this been an internal feature not accessible till 2023.1?

    I'm asking because my editor-specific csproj files are generated with facades instead of shims when .Netstandard is the chosen API Compatibility Level.

    See the issue here.
     
    oscarAbraham likes this.
  2. TheSleepyKoala

    TheSleepyKoala

    Joined:
    Aug 24, 2018
    Posts:
    23
    I solved my issue.

    #if !UNITY_2023_1_OR_NEWER
    static string HandleEditorReference(string referencePath, string netstandardVersion)
    {
    var facadesPath = "UnityReferenceAssemblies\\unity-4.8-api\\Facades\\";
    var referenceName = Path.GetFileNameWithoutExtension(referencePath);

    return referenceName switch
    {
    "Microsoft.Win32.Primitives" or "System.AppContext" or "System.Collections.Concurrent" or
    "System.Collections.NonGeneric" or "System.Collections.Specialized" or "System.ComponentModel" or
    "System.ComponentModel.EventBasedAsync" or "System.Diagnostics.Contracts" or "System.Diagnostics.Debug" or
    "System.Diagnostics.Tools" or "System.Diagnostics.Tracing" or "System.Globalization" or
    "System.Globalization.Calendars" or "System.IO" or "System.IO.Compression" or
    "System.IO.Compression.ZipFile" or "System.IO.FileSystem" or "System.IO.FileSystem.Primitives" or
    "System.Linq" or "System.Linq.Expressions" or "System.Net.Http" or
    "System.Net.Primitives" or "System.Net.Sockets" or "System.ObjectModel" or
    "System.Reflection" or "System.Reflection.Extensions" or "System.Reflection.Primitives" or
    "System.Resources.ResourceManager" or "System.Runtime" or "System.Runtime.Extensions" or
    "System.Runtime.Handles" or "System.Runtime.InteropServices" or "System.Runtime.InteropServices.RuntimeInformation" or
    "System.Runtime.Numerics" or "System.Security.Cryptography.Algorithms" or "System.Security.Cryptography.Encoding" or
    "System.Security.Cryptography.Primitives" or "System.Security.Cryptography.X509Certificates" or "System.Text.Encoding" or
    "System.Text.Encoding.Extensions" or "System.Text.RegularExpressions" or "System.Threading" or
    "System.Threading.Tasks" or "System.Threading.Tasks.Parallel" or "System.Threading.Thread" or
    "System.Threading.ThreadPool" or "System.Threading.Timer" or "System.ValueTuple" or
    "System.Xml.ReaderWriter" or "System.Xml.XDocument" or "System.Xml.XmlDocument" or
    "System.Xml.XmlSerializer" or "System.Xml.XPath" or "System.Xml.XPath.XDocument" =>
    referencePath.Replace(facadesPath, $"NetStandard\\compat\\{netstandardVersion}\\shims\\netstandard\\"),
    "System.Runtime.InteropServices.WindowsRuntime" => referencePath.Replace(facadesPath, $"NetStandard\\Extensions\\2.0.0\\"),
    "netstandard" => referencePath.Replace(facadesPath, $"NetStandard\\{netstandardVersion}\\"),
    _ => referencePath.Replace(facadesPath, $"NetStandard\\compat\\{netstandardVersion}\\shims\\"),
    };
    }
    #endif
     
    Last edited: Apr 7, 2023