Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.25k stars 88 forks source link

Dependency errors in Unity 2023.2 #155

Closed Totoro83 closed 2 months ago

Totoro83 commented 6 months ago

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.

neuecc commented 6 months ago

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.

Totoro83 commented 6 months ago

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.

ApzSK commented 6 months ago

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

Totoro83 commented 6 months ago

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.)

neuecc commented 6 months ago

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. https://github.com/GlitchEnzo/NuGetForUnity/pull/616 Would you try the latest master NuGetForUnity with the git url?

image

Totoro83 commented 6 months ago

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.

neuecc commented 2 months ago

maybe latest NuGetForUnity solves it. https://github.com/GlitchEnzo/NuGetForUnity/releases/tag/v4.1.1