xoofx/UnityNuGet

Meziantou analyzer includes assemblies not compatible with Unity

bdovaz opened this issue · 0 comments

bdovaz commented

Contains Roslyn dependencies not compatible with Unity, Roslyn > 3.8:

For example:

warning CS8032: An instance of analyzer Meziantou.Analyzer.Rules.SequenceNumberMustBeAConstantAnalyzer cannot be created from {MY_PROJECT}\Library\PackageCache\org.nuget.meziantou.analyzer@2.0.85\dotnet\roslyn4.2\cs\Meziantou.Analyzer.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified..

https://docs.unity3d.com/Manual/roslyn-analyzers.html

So far it seems that Unity 2020.x, Unity 2021.x, Unity 2022.x, Unity 2023.x only support Roslyn 3.8.

image

The problem is that it seems that although there is a convention for the folders it doesn't seem to be validated in any way: https://learn.microsoft.com/en-us/nuget/guides/analyzers-conventions#analyzers-path-format

For example, in the case of Meziantou.Analyzer it is: /analyzers/dotnet/roslyn{version}/cs/{assemblies}.

In SonarAnalyzer.CSharp it is: /analyzers/{assemblies}

In Roslynator.Analyzers is: /analyzers/dotnet/cs/{assemblies}

That is why this check exists:

https://github.com/xoofx/UnityNuGet/blob/4b5825c27115c677e154b88b937292ef6b22086a/src/UnityNuGet/RegistryCache.cs#L601C10-L601C10

Now we should add a specific one for Meziantou because I have not seen any other package of type Analyzer that contains assemblies for different versions of Roslyn.

@xoofx can you think of a "nice" way to do this check? Because not having a convention reinforced with validations by NuGet it is complicated to have a filtering criteria that will work "always".