Closed hadashiA closed 4 months ago
Unity documentation at https://docs.unity3d.com/Manual/roslyn-analyzers.html says Your source generator must use Microsoft.CodeAnalysis 3.8 to work with Unity
even for 2022 and 2023 versions. Do you think their documentation is wrong on this account?
Unity compiler is silently updated, it can find in Editor\Data\DotNetSdkRoslyn\
Incremental Compiler also works, and the C# version can be updated (C# 11.0). https://github.com/Cysharp/ZLogger/?tab=readme-ov-file#installation
Unity documentation is often not updated.
Description
A single nuget package can contain multiple Roslyn analyzers with same content but different Roslyn versions. This is to support older versions of Roslyn users.
Currently, this seems to be a problem in some cases.
For example, if we install
System.Text.Json
with NuGetForUnity, source generators x3 with the same content are imported.I tried the following simple System.Text.Json Source Generator example, getting errors.
This is because multiple SourceGenerators with the same contents are run.
[Describe the issue you have. If applicable provide logs produced by enabeling verbose logging in the NuGetForUnity settings.]
Improvement proposal
This problem can be solved by limiting the number of dlls with the
RoslynAnalyzer
asset label to one. Currently, analzyer is disable on any platform, so doing this was sufficient.So, why not pick one analyzer that can be used in the target Unity editor and change it to only put
RoslynAnalyzer
there?According to our research, the analyzer/source generator versions that work with Unity are as follows. (You can find the Microsoft.CodeAnalysis.CSharp.dll bundled in a folder called DotNetSdkRoslyn in the Unity editor application, so you can check the version.)
I have implemented this in #616 and would appreciate your confirmation. Thanks!