Code Monkey home page Code Monkey logo

csharpcompilersettingsforunity's Introduction

Hi there 👋

csharpcompilersettingsforunity's People

Contributors

mob-sakai avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharpcompilersettingsforunity's Issues

Cannot use global using directive.

Describe the bug
"global using directive" not work.

To Reproduce
Steps to reproduce the behavior:

  1. Make a script contain this line:
    global using MB = UnityEngine.MonoBehaviour
  2. Go back to Unity Editor and got error: "A namespace cannot directly contain members such as fields or methods"

Expected behavior
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive

Environment (please complete the following information):

  • Version: 1.5.0
  • Platform: Unity Editor
  • Unity version: 2021.3.5
  • Build options: Mono + .Net 4.x

Doesn't work on macOS with big files

Compiler fails to compile the file with error.

error CS1504: Source file '***/Assets/TrueSync/Physics/Farseer/Common/PhysicsLogic/RealExplosion.cs' could not be opened -- GetCPInfoExW

To Reproduce
Steps to reproduce the behavior:

  1. Clone repo https://github.com/VolodymyrBS/CSharpCompilerSettingsForUnityBugRepro.git
  2. Import project on macOS
  3. Check Console
  4. See an error

Environment:

  • Version 1.0.1
  • Platform: Editor Mac
  • Unity version: [e.g. 2019.3.5f1]
  • Build options: any
  • Injected compiler version - 3.5.0, 3.7.0

Additional context
Probably it's related to this issue
mono/mono#12603
ILSpy shows that System.Text.Encoding.CodePages.dll library inside Microsoft.Net.Compiler package use WinApi

image

Note: Can't share the original project but only part of it enough to reproduce the error.
Note: Error will also occure if you try to directly call mono <path to downloaded csc.exe> <path to RealExplosion.cs>

[Bug?] Can't get it to work on Unity 2021.3.16f1...

So I actually tested this out today, but somehow I can't get it to work?
It seems like it should allow C#10 Compilation etc... as the project says but it just won't work!

There was a section about Unity 2021.1 and later...
mob-sakai/CSharpCompilerSettingsForUnity: Change the C# compiler (csc) used on your Unity project, as you like!
I followed exactly what was said, used the CUSTOM_COMPILE compiler directive and had also an #else flow...

Why isn't it working? Even when building the project into an executable the defaut compiler for Unity is still used...
Help!

upload_2023-1-7_11-43-39
upload_2023-1-7_11-44-6

So the UI Object doesn't become red neither on build nor in the Unity Player...

Thanks in advance

2022 Support

Description
Fails to compile in any 2022 version of Unity, such as 2022.2.0b8

To Reproduce
Steps to reproduce the behavior:

  1. Add package to any 2022 project
  2. Compile
  3. See errors (see below)

Expected behavior
Compiles without any issues.

Environment (please complete the following information):

  • Package Version 1.5.0
  • Unity Version 2022.2.0b8

Additional context
Warning:
System.Exception: Reflection not found: Driver in Bee.BeeDriver.ActiveBuild
at Coffee.CSharpCompilerSettings.ReflectionExtensions.Get (System.Object self, System.String memberName, System.Reflection.MemberInfo mi) [0x00072] in <1953dcd1da5444c992e14e6e66b4207b>:0
at Coffee.CSharpCompilerSettings.CustomCompiler_2021.OnCompilationStarted (System.Object state) [0x00006] in <1953dcd1da5444c992e14e6e66b4207b>:0
at (wrapper delegate-invoke) System.Action`1[System.Object].invoke_void_T(object)
at UnityEditor.Compilation.CompilationPipeline+<>c.b__26_0 (System.Object context) [0x0000b] in :0
0x00007ff650443bcd (Unity) StackWalker::GetCurrentCallstack
0x00007ff650448c99 (Unity) StackWalker::ShowCallstack
0x00007ff651402a81 (Unity) GetStacktrace
0x00007ff651abc3e2 (Unity) DebugStringToFile
0x00007ff64f3707b6 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x0000015b867f353a (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x0000015b867f33cb (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x0000015b867f28ee (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x0000015b867f257d (Mono JIT Code) UnityEngine.Debug:Log (object)
0x0000015c8cdbd81b (Mono JIT Code) UnityEditor.Compilation.CompilationPipeline/<>c:b__26_0 (object)
0x0000015c8cdbd5f8 (Mono JIT Code) UnityEditor.Scripting.ScriptCompilation.EditorCompilation:InvokeCompilationStarted (object)
0x0000015c8cd0765b (Mono JIT Code) UnityEditor.Scripting.ScriptCompilation.EditorCompilation:CompileScriptsWithSettings (UnityEditor.Scripting.ScriptCompilation.ScriptAssemblySettings)
0x0000015c8cd0530b (Mono JIT Code) UnityEditor.Scripting.ScriptCompilation.EditorCompilation:CompileScripts (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,string[])
0x0000015c8f259b83 (Mono JIT Code) UnityEditor.Scripting.ScriptCompilation.EditorCompilation:TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,string[],bool)
0x0000015c8f258f7b (Mono JIT Code) UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,string[],bool)
0x0000015c8f25934f (Mono JIT Code) (wrapper runtime-invoke) :runtime_invoke_EditorCompilation/CompileStatus_int_int_int_int_object_byte (object,intptr,intptr,intptr)
0x00007ffb223a0304 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
0x00007ffb222deb44 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
0x00007ffb222decdc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke
0x00007ff65036bd14 (Unity) scripting_method_invoke
0x00007ff65034c6b4 (Unity) ScriptingInvocation::Invoke
0x00007ff6503471aa (Unity) ScriptingInvocation::Invoke
0x00007ff650488c7d (Unity) Scripting::UnityEditor::Scripting::ScriptCompilation::EditorCompilationInterfaceProxy::TickCompilationPipeline
0x00007ff6512afc9b (Unity) TickCompilationPipeline
0x00007ff6512afe3a (Unity) TickCompilationPipeline
0x00007ff650f886b8 (Unity) Application::TickTimer
0x00007ff6514092ca (Unity) MainMessageLoop
0x00007ff65140e240 (Unity) WinMain
0x00007ff6527be5fe (Unity) __scrt_common_main_seh
0x00007ffbd8747034 (KERNEL32) BaseThreadInitThunk
0x00007ffbda5226a1 (ntdll) RtlUserThreadStart

Error:
ArgumentNullException: Value cannot be null.
Parameter name: source
System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] predicate, System.Boolean& found) (at :0)
System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] predicate) (at :0)
Coffee.CSharpCompilerSettings.CustomCompiler_2021.OnAssemblyCompilationFinished (System.String dllPath, UnityEditor.Compilation.CompilerMessage[] messages) (at <1953dcd1da5444c992e14e6e66b4207b>:0)
UnityEngine.Debug:LogException(Exception)
Coffee.CSharpCompilerSettings.CustomCompiler_2021:OnAssemblyCompilationFinished(String, CompilerMessage[])
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, Int32, String[], Boolean)

Support 2021.1

On 2021.1.a9 the "Apply" button is causing an exception, so I couldn't test it yet.

[Exception] InvalidOperationException: Sequence contains no matching element
Enumerable.First[TSource]() at <351e49e2a5bf4fd6beabb458ce2255f3>:0

ReflectionExtensions.Call() at <26e68dbb771b4491aa5f1dc8f99cc436>:0

Utils.RequestCompilation() at <26e68dbb771b4491aa5f1dc8f99cc436>:0

CscSettingsProvider+<>c.<OnGUI>b__9_1() at Library/PackageCache/com.coffee.csharp-compiler-settings@88d8659a14/Editor/CscSettingsProvider.cs:100
98:       serializedObject.ApplyModifiedProperties();
99:       File.WriteAllText(CscSettingsAsset.k_SettingsPath, JsonUtility.ToJson(serializedObject.targetObject, true));
-->100:       Utils.RequestCompilation();
101:   },
102:   onReload: () =>

InspectorGUI.DrawControl() at Library/PackageCache/com.coffee.csharp-compiler-settings@88d8659a14/Editor/InspectorGUI.cs:175
174:       if (onApply != null && GUILayout.Button(s_ApplyText))
-->175:           onApply();
176:   }

CscSettingsProvider.OnGUI() at Library/PackageCache/com.coffee.csharp-compiler-settings@88d8659a14/Editor/CscSettingsProvider.cs:94
93:   // Controls
-->94:   InspectorGUI.DrawControl(serializedObject.hasModifiedProperties,
95:       onRevert: () => { serializedObject = new SerializedObject(CscSettingsAsset.instance); },
96:       onApply: () =>

SettingsProvider.OnGUI() at <a19e86c7bf354115a4c6a5953c0575cb>:0

Originally posted by @SugoiDev in #6 (comment)

Support Roslyn analyzer

  • The analyzer package will be extracted to Library directory
    • No need to install dotnet or nuget
    • The analyzer dlls are not referenced by Unity as assets
  • Configure settings in Project Settings window
    • Choose analyzer packages (name and version)
    • Filter assemblies to analyze
  • The analyzer dlls and rulesets will be referenced in the response file for the compilation process
    • Temp/UnityTempFile-***
  • Support IDE
  • Support all platforms
    • Windows
    • macOS
    • Linux

Compiler show error on Unity Editor for Windows

NOTE: Your issue may already be reported! Please search on the issue tracker before creating one.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'ProjectSettings',fill "Microsoft.Unity.Analyzers" and select version 1.12.0
  2. Select Compiler Type: BuiltIn
  3. Click on 'apply'
  4. Waiting progress endless.
  5. Restart UnityEditor, error report:
stdout:

stderr:

Specify which project file to use because this 'D:\GitHubs\example' contains more than one project file.

Environment

Platform: Editor(Windows)
Unity version: 2021.2.11f1
Build options:

Additional context
The BuiltIn Compiler worked perfect in Unity Editor for MacOs.
Suggest solution
Change the Setup function inside CompilerInfo to this:

 public void Setup(ProcessStartInfo psi, string responseFile, RuntimePlatform platform)
        {
            if (platform == RuntimePlatform.WindowsEditor
                && Path.EndsWith(".exe"))
            {
                psi.FileName  = System.IO.Path.GetFullPath(Path);
                psi.Arguments = "/shared /noconfig @" + responseFile;
            }
            else
            {
                psi.FileName  = System.IO.Path.GetFullPath(RuntimePath);
                psi.Arguments = "\"" + Path + "\"" + " /noconfig @" + responseFile;
            }
            psi.CreateNoWindow  = true;
            psi.UseShellExecute = false;
        }

I changed the Path to "\"" + Path + "\"" to avoid problem with Windows file path since C:\Program Files\Unity\Hub\Editor\2021.2.11f1\Editor\Data\DotNetSdkRoslyn\csc.dll has space in the path string.

I also found that CustomCompiler_2021 need to change in this function

private string GetOutDir(string dagName)
        {
            if (dagName.EndsWith("E")) return "Library/ScriptAssemblies";

            var unityVersions = Application.unityVersion.Split('.');
            if (int.Parse(unityVersions[0]) == 2021)
                //return "Library/PlayerScriptAssemblies";
                return "Library/ScriptAssemblies";
            else
                return "Library/Bee/PlayerScriptAssemblies";
        }

since the Library/PlayerScriptAssemblies was not found.

Support all nullable settings

  • enable: The nullable annotation context is enabled. The nullable warning context is enabled.
    • Variables of a reference type, string for example, are non-nullable. All nullability warnings are enabled.
  • warnings: The nullable annotation context is disabled. The nullable warning context is enabled.
    • Variables of a reference type are oblivious. All nullability warnings are enabled.
  • annotations: The nullable annotation context is enabled. The nullable warning context is disabled.
    • Variables of a reference type, string for example, are non-nullable. All nullability warnings are disabled.
  • disable: The nullable annotation context is disabled. The nullable warning context is disabled.
    • Variables of a reference type are oblivious, just like earlier versions of C#. All nullability warnings are disabled.

Not working on Windows

Plugin do something and adds Compilation directives CSHARP_8_OR_LATER...
but actually can not compile any C# 8 code
even csc.rsp -langversion:8.0 stop compiler function with error of uncompatible lang version

Screenshots
изображение

Environment (please complete the following information):

  • Unity Version 1.0.0
  • Platform: Editor(Windows)
  • Unity version: 2019.4.9f1
  • Build options: IL2CPP, .Net 4.x, URP

Add option for generating nullable property in csproj

Is your feature request related to a problem? Please describe.
If you want to use nullable reference types after C#8.0 you either have to manually add the

<Nullable>enable</Nullable>

property to enable nrt or you have to annotate each file with

#nullable enable

Describe the solution you'd like
In the settings there should be an option for adding the Nullable property when adding the desired LangVersion property. One problem might be is when you want only some projects to have the Nullable property but that would require porject-by-project settings which are as of yet not supported anyway.

Generated local package csproj does not get updated

Describe the bug
When adding a UPM package locally, and then generating a csproj for it through unity, de generated project for the upm package does not get updated when generating.

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/KuraiAndras/CCFUBugSample
  2. Open Unity
  3. In Preferences -> External Tools -> External Script Editor select Visual Studio 2019
  4. In the same settings enable Local packages generation
  5. Regenerate project files
  6. Open the project in Visual Studio

Unity does not report any compile errors(correctly), while Visual Studio shows an error in CCFUBugSample.SampleService.TestSwitch. This is because in the unity generated CCFUBugSample.csproj the LangVersion property is set to 7.3 instead of 8.

Expected behavior
Any generated csproj gets the desired LangVersion property value

Environment (please complete the following information):

  • Version 1.1.0
  • Platform: Editor Windows
  • Unity version: 2020.1.8

Additional context
If this would cause problems for some users, maybe consider making this behavior optional through settings

Support C# 9 Source Generators

Thanks for building this great project.
I tried this project and it works great with C# 9 syntax.
However, I cannot make it work with C# 9 Source Generators. May I know if this support?
I am using Unity 2020.3.

Can not install compiler

NOTE: Your issue may already be reported! Please search on the issue tracker before creating one.

When I use any Compiler and click 'apply',editor will start the progress not be done.I can see from the task manager that there is network traffic going through and after a while it doesn't. But progress is still stuck.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'ProjectSettings',fill "OpenSesame.Net.Compilers.Toolset" and select version 4.0.1
  2. Click on 'apply'
  3. Waiting progress endless.
  4. Restart UnityEditor,error report:

[CscSettings] Install package: OpenSesame.Net.Compilers.Toolset.4.0.1
UnityEngine.Debug:Log (object)
Coffee.CSharpCompilerSettings.Logger:LogInfo (string,object[])
Coffee.CSharpCompilerSettings.Utils:InstallPackage (string,string)
Coffee.CSharpCompilerSettings.Utils:InstallNugetPackage (string)
Coffee.CSharpCompilerSettings.CompilerInfo:GetInstalledInfo (string)
Coffee.CSharpCompilerSettings.Core:Initialize ()
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadMethodAttributes ()

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Package 'OpenSesame.Net.Compilers.Toolset.4.0.1' installation failed.
at Coffee.CSharpCompilerSettings.Utils.InstallPackage (System.String packageId, System.String url) [0x000a6] in <1953dcd1da5444c992e14e6e66b4207b>:0
at Coffee.CSharpCompilerSettings.Utils.InstallNugetPackage (System.String packageId) [0x00016] in <1953dcd1da5444c992e14e6e66b4207b>:0
at Coffee.CSharpCompilerSettings.CompilerInfo.GetInstalledInfo (System.String packageId) [0x00000] in <1953dcd1da5444c992e14e6e66b4207b>:0
at Coffee.CSharpCompilerSettings.Core.Initialize () [0x001d1] in <1953dcd1da5444c992e14e6e66b4207b>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <695d1cc93cca45069c528c15c9fdd749>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0
at UnityEditor.EditorAssemblies.ProcessInitializeOnLoadMethodAttributes () [0x00047] in <2cd7ebc9c2ef4276a8edbc7de85c89ce>:0
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadMethodAttributes ()

Environment (please complete the following information):

  • Version C# Compiler Settings 1.5.0
  • Platform: Editor(Windows)
  • Unity version: 2020.3.22f1
  • Build options:

Additional context
Add any other context about the problem here.

Json doesnt have an `id` or `version` to read from

the NugetPackageDrawer class is trying to reference id and version from a json that didnt have it:

.Concat(obj.items).SelectMany(x => x.items)
.Select(x => new(x.catalogEntry.id, x.catalogEntry.version, ...)

my first change was to make it work requried to add a @id field to the catalog page class and an upper field (for version), the items array was left unused and the select becomes:

.Concat(obj.items).
.Select(x => new(x.@id, x.upper, ...)

and here is the json that I would normally get for Microsoft.Net.Compilers.
however, this wont show all of the versions for open sesame because the json for those actually matches, so a better fix for me locally is to init the items variables for catalog root and page to a new blank array s o that linq could keep going.

public CatalogPage[] items = { };
public Package[] items = { };

Updating to 1.4.0 from 1.3.0 fails with with Unity 2020.1.17

Describe the bug
Updated my project from 1.3.0 to 1.4.0 with Unity 2020.1.17 and not all of my sources are compiled

To Reproduce
Can't really

Expected behavior
All sources compile

Screenshots
image

Environment (please complete the following information):

  • Version 1.4.0
  • Platform: Editor/Windows
  • Unity version: 2020.1.17
  • Build options: .Net 4.x

Additional context
The problem might come from the fact that we are using external .cs files added as unity packages. We have several projects included like:

[package.json]
"bimvisualizer.shared": "file:../../BimVisualizer.Shared",

These point to folders with .net standard 2.0 projects (which are using C#9.0) (also the bin and obj folders are renamed to .bin and .obj so unity will not try to use the dlls inside them). The errors seem to only come from one project where c# 9 and 8 are used, and not from the unity project.

Should I include another folder for assemblies in the settings?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.