Open mob-sakai opened 3 years ago
@VolodymyrBS @SugoiDev
Up to Unity 2020.x, we used to replace the compile process from the script, but that is no longer possible. After a brief investigation, the compile task has changed significantly since Unity 2021.1:
CompilationTask (class)
has been changed to Bee
and BeeDriver (class)
Library/Bee/*.dag.json
ExternalCSCompiler
assembly (used for #6: 2020.2 support) has been disabledhttps://forum.unity.com/threads/unity-c-8-support.663757/page-7#post-6749023 So apparently this is happening.
I found a way to replace the compiler on newer Unity versions. It was only lightly tested, but seems to work. You need to install the desired .NET sdk version first (https://dotnet.microsoft.com/download/dotnet/6.0). Then, we do some symlinking (or copying). I'm using 2022.1.0a9 and 6.0.100-rc.1.21463.6 as example below. Your installed .NET might have different version. Note: You need to rename or delete the original folders.
symlink (or copy)
c:\Program Files\dotnet\
as
c:\Program Files\Unity\Hub\Editor\2022.1.0a9\Editor\Data\NetCoreRuntime\
symlink (or copy)
c:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Roslyn\bincore\
as
c:\Program Files\Unity\Hub\Editor\2022.1.0a9\Editor\Data\DotNetSdkRoslyn\
@mob-sakai
I'm trying to get OpenSesame working on 2021.1, and found that we can set cscPath
during compilationStarted
in a ScriptCompilationData
that is stored in activeBeeBuild.Driver.DataForBuildProgram
Decompiled UnityEditor.dll using dnSpy. (Rider can do that too)
I don't think we can do this per-assembly anymore (assemblyCompilationStarted
is now obsolete and invoked during assemblyCompilationFinished
).
So the problem is that now OpenSesame is used to compile all of the assemblies, which results in accessibility errors when IgnoresAccessChecksToAttribute
is added in places it doesn't belong to.
It might be possible to remove assemblies
from ScriptCompilationData, so we can compile them manually afterwards, but it breaks other parts of Unity's compiler and I did not get it to work..
The other solution might be to modify OpenSesame compiler to check if assembly actually wants IgnoreAccessibility
@KuraiAndras @SugoiDev @neon-age Thank you for your cooperations! I have been trying some ideas for a few days. I found a way to set up csc configuration for each assembly in 2021.x. :+1: https://github.com/mob-sakai/CSharpCompilerSettingsForUnity/blob/develop/Plugins/CSharpCompilerSettings/CustomCompiler_2021.cs
In Unity 2021, any user code cannot be executed prior to the first compilation. In other words, we have to pass the compilation even if we use the built-in compiler.
For example, if you have code that accesses non-public members (with the custom compiler OpenSesame.Net.Compilers.Toolset
), you should use CUSTOM_COMPILE
symbol as follows:
using System;
using NUnit.Framework;
namespace IgnoreAccessibility
{
public class IgnoreAccessibilityContent
{
private int privateNumber = 999;
}
public class IgnoreAccessibilityTest
{
[Test]
public void GetPrivateField()
{
#if CUSTOM_COMPILE
Assert.AreEqual(new IgnoreAccessibilityContent().privateNumber, 999);
#else
throw new NotImplementedException();
#endif
}
}
}
@KuraiAndras @SugoiDev @neon-age
v1.5.0
supports Unity 2021.1 or later. 👍
See For Unity 2021.1 or later section.
Nice work!
On 2021.1.a9 the "Apply" button is causing an exception, so I couldn't test it yet.
Originally posted by @SugoiDev in https://github.com/mob-sakai/CSharpCompilerSettingsForUnity/issues/6#issuecomment-750290039