Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependency errors in Unity 2023.2

Totoro83 opened this issue · comments

Trying to install ZLogger on Unity 2023.2.13f1 with NuGetForUnity I get the following errors:

Assembly 'Assets/Packages/System.Text.Json.8.0.0/analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll' will not be loaded due to errors:
Unable to resolve reference 'Microsoft.CodeAnalysis'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Microsoft.CodeAnalysis.CSharp'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Packages/ZLogger.2.4.1/analyzers/dotnet/roslyn4.3/cs/ZLogger.Generator.dll' will not be loaded due to errors:
Unable to resolve reference 'Microsoft.CodeAnalysis'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Microsoft.CodeAnalysis.CSharp'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Packages/Microsoft.Extensions.Logging.Abstractions.8.0.0/analyzers/dotnet/roslyn4.4/cs/Microsoft.Extensions.Logging.Generators.dll' will not be loaded due to errors:
Unable to resolve reference 'Microsoft.CodeAnalysis'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Microsoft.CodeAnalysis.CSharp'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Packages/Microsoft.Extensions.Options.8.0.0/analyzers/dotnet/roslyn4.4/cs/Microsoft.Extensions.Options.SourceGeneration.dll' will not be loaded due to errors:
Unable to resolve reference 'Microsoft.CodeAnalysis'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Microsoft.CodeAnalysis.CSharp'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

To be sure that the issue was in the ZLogger installation, and not in something else, I created a new project from scratch, where I just installed NugetForUnity from OpenUPM (version 4.0.2), and then ZLogger.

Notice that I installed other packages from NugetForUnity on 2023.2 without any problem, and that the installation runs perfectly on Unity 2022.3.20f1. I'm not sure if the problem is related on some ZLogger dependencies or some NuGetForUnity configuration.

It appears that the generator is not marked with a label as an Analyzer.
Normally NuGetForUnity does that, but for some reason it didn't seem to do it.
Please check the target label first and try adding the analyzer manually.

You are right that they are not labeled, but only adding the label RoslynAnalyzer didn't solve it.
I had to disable the generators on all the platforms (as explained in the Unity manual) to get rid of the errors. Anyway, even if I didn't test the generators yet, things seem to work fine now.

commented

Same issue here, on Unity 2023.2.15f1 adding the label RoslynAnalyzer or/and Analyzer doesn't fix these 4 issues. Please fix or/and write short guide how to properly set it up on the latest Unity version

I also think that this should be fixed (even if I still am not sure if the issue is in the NuGet ZLogger package or in NuGetForUnity) but, as a workaround, following there is the full procedure I used to have ZLogger working for me (I've tested it with Unity 2023.2.13f1, but I suppose that for the other 2023.2 versions it's the same.)

  • Install NuGetForUnity from OpenUPM
  • Install ZLogger from NuGetForUnity (this will show the errors in console)
  • From every single dll giving errors in console, remove every supported platform. This is the intended way to use Roslyn generators and analyzers, as explained in Unity Documentation, only NuGetForUnity forget to do this for some reason.
    To do this, it's enough to select the dll, then to disable the flags in figure (all of them, the exact flags depend on the platforms you have in your project), and then to press apply.
    Example
    Notice that more dlls will appear as you configure them. Following there is the entire list I found.
    • Assets/Packages/Microsoft.Extensions.Logging.Abstractions.8.0.0/analyzers/dotnet/roslyn4.0/cs/Microsoft.Extensions.Logging.Generators.dll
    • Assets/Packages/Microsoft.Extensions.Logging.Abstractions.8.0.0/analyzers/dotnet/roslyn3.11/cs/Microsoft.Extensions.Logging.Generators.dll
    • Assets/Packages/Microsoft.Extensions.Logging.Abstractions.8.0.0/analyzers/dotnet/roslyn4.4/cs/Microsoft.Extensions.Logging.Generators.dll
    • Assets/Packages/System.Text.Json.8.0.0/analyzers/dotnet/roslyn4.0/cs/System.Text.Json.SourceGeneration.dll
    • Assets/Packages/System.Text.Json.8.0.0/analyzers/dotnet/roslyn4.4/cs/System.Text.Json.SourceGeneration.dll
    • Assets/Packages/System.Text.Json.8.0.0/analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll
    • Assets/Packages/Microsoft.Extensions.Options.8.0.0/analyzers/dotnet/roslyn4.4/cs/Microsoft.Extensions.Options.SourceGeneration.dll
    • Assets/Packages/ZLogger.2.4.1/analyzers/dotnet/roslyn4.3/cs/ZLogger.Generator.dll
  • At this point, complete the installation changing the C# version and installing the Unity helpers (as exlpained in the ZLogger Documentation)
  • If you don't want the code generation functionalities, that's it. If you instead are interested in them, add the RoslynAnalyzer Asset Label on Assets/Packages/ZLogger.2.4.1/analyzers/dotnet/roslyn4.3/cs/ZLogger.Generator.dll. You can, if you want, add the label also in the other generators that you modified before, but I don't think it's stictly necessary to use the ZLogger generator, so it's up to you.

I have not had any problems in my environment.
It is installing the latest NuGetForUnity with the git url.
OpenUPM's NuGetForUnity is 5 months old and seems a bit out of date.
Of course that is the released version, but the master is a bit more advanced.
It also includes Analyzer related fixes.
GlitchEnzo/NuGetForUnity#616
Would you try the latest master NuGetForUnity with the git url?

image

I just tested it with the latest NuGetForUnity from the url https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity, and I still have the problems. My ZLogger generator settings are like this:

Config

This bug is not present in older unity versions. In the current LTS both the platforms and the labels are set correctly.