GlitchEnzo / NuGetForUnity

A NuGet Package Manager for Unity
MIT License
3.23k stars 317 forks source link

Analzyers will not be loaded due to errors #644

Closed CDTR-MattConroy closed 5 months ago

CDTR-MattConroy commented 6 months ago

Installing various packages that come with analyzers produce the following errors:

Assembly 'Packages/nuget-packages/InstalledPackages/AWSSDK.S3.3.7.203.2/analyzers/dotnet/cs/AWSSDK.S3.CodeAnalysis.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.

Assembly 'Packages/nuget-packages/InstalledPackages/AWSSDK.Kinesis.3.7.200.27/analyzers/dotnet/cs/SharedAnalysisCode.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 'System.Collections.Immutable'. 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 'Packages/nuget-packages/InstalledPackages/AWSSDK.Kinesis.3.7.200.27/analyzers/dotnet/cs/AWSSDK.Kinesis.CodeAnalysis.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.

Tried deleting the restored packages and restoring again, and restarting Unity to no avail.

CDTR-MattConroy commented 6 months ago

This seems to be exclusive to Unity 2023. Rolling back to Unity 2022.3.9, removes the problem.

xaroth8088 commented 6 months ago

This also seems to affect Unity 6000.x. See https://github.com/Cysharp/MemoryPack/issues/275 for an example of where this is happening.

CDTR-MattConroy commented 6 months ago

Interesting, is there's a known workaround at all? I've had this issue intermittently on Unity 2022, but restarting the Editor always seemed to clear it out.

xaroth8088 commented 6 months ago

None that I'm aware of. 😞

igor84 commented 6 months ago

Unity documentation here https://docs.unity3d.com/Manual/roslyn-analyzers.html says: Your source generator must use Microsoft.CodeAnalysis 3.8 to work with Unity.

I think all these packages are using much newer version and are thus not supported by Unity. Even if it seems they work in earlier Unity versions there is no guarantee they will work correctly.

JoC0de commented 6 months ago

I can imagine the the new editor vs runtime assembly compatibility level setting could be the cause, did you try setting both to netstandard 2?

xaroth8088 commented 6 months ago

I can imagine the the new editor vs runtime assembly compatibility level setting could be the cause, did you try setting both to netstandard 2?

Alas, no dice. Problem persists with both API and editor assemblies set to .NET Standard 2.1 (tested in 6000.0.2f1, attempting to install MemoryPack).

CDTR-MattConroy commented 6 months ago

Would it be possible to an add option to ignore analyzers from packages? Not ideal I know, but if they don't work in newer versions of Unity, but the actual package does it should only be the developer experience that's affected? As it stands this seems to be blocking me from upgrading past 2022 unnecessarily?

JoC0de commented 5 months ago

@CDTR-MattConroy I found the error. Basically the whole analyzer dll re-configuring process was skipped. I fixed it in #646 and tested it with unity 2023.2.20f1 and the package AWSSDK.S3.3.7.308.7.