I just added some Roslyn analyzers into my Unity project like described here:
Everything works nicely, however I cannot find a way to exclude Unity packages from the analysis. What happens is that when compiling the project, I see bunch of analysis errors and warnings in the console for the files which are actually part of Unity packages. Is there a way to disable the analysis on those?
A workaround that I currently found is that I put my analyzer dlls into the Folder containing the asmdef file instead of putting them into the Assets folder directly. But I don’t like that solution since I have multiple folders containing the asmdef files like this:
A way to control the asmdef’s your analyzer runs on, is to have a asmdef(fx. analyzer.asmdef) with an analyzer next to it, and reference the asmdef. Then only the Asmdef’s that references the analyzer.asmdef with the analyzer will include it.
@HaraldNielsen thanks for your reply. I think I understand. But what if the analyzer is already compiled - let’s say that I have analyzer dll like ErrorProne.Net.CoreAnalyzers.dll ?
For that you place ErrorProne.Net.CoreAnalyzers.dll next to a asmdef, and then all that reference that asmdef will run with ErrorProne.Net.CoreAnalyzers
But imaging we have our N asmdef, and we want to apply the analizers to all those N assemblies. Then we’d have to copy N times de analyzers and place next to the asmdef, isn’t it?
Isn’t there a way to exclude folders? Such as package folder and 3rd party folder?
Read the “Analyzer scope” section, you just have to only reference the asmdef that is next to the analyzer, if you only want to run on part of the assemblies (The ones that reference the asmdef directly)
Every script described above is a MonoBehaviour with an empty Start method, which should show errors in the Unity Console.
With the settings described above, the analyzer is not catching anything. But if I just delete the Analyzers.asmdef and let the DLL alone, it starts catching all the scripts in the Assets (except the MyFeatureC which has no asmdef) and all the Packages (even the ones from Unity).
I wonder if you could please clone my repo, do some tweaks to make it work, and then tell us where is the mistake.
Hi @sandolkakos - sorry for the delay!
So I just took a look, and its because we skip compilation of Asmdef’s that dont have any *.cs files. (forgot about this myself)
If you put a *.cs file in, it works. It started reporting the warnings for me after I did that