Roslyn Analysis not analysing assets folder

I am encountering an issue where my unity Roslyn analyser set-up is correctly analysing all scripts in package folders, but apparently not touching anything in the assets folders. (From debugging, not even looking at).

However, inside of VS, it is reading and showing errors fine, it is just the unity console is not showing errors for things in the assets folder.

I have added a reference to the analysis .dll file in all my project .asmdef files as precompiled assets, and tagged it as a RoslynAnalyser.

I have a rulesets file in my room assets folder.

Another more minor, but potentially related issue is that the ruleset file doesn’t change the type of message my analyser is sending inside of the unity console. Again, inside of VS, this is working absolutely fine, it’s just an issue in the unity console.

Any help/ideas appreciated thanks :slight_smile:

Anyone got any ideas on this?

According to the “Analyzer scope” section of the manual, the analyzer’s dll is not what needs to be referenced, but the asmdef that owns the folder where your dll is. That is, Analyzers inside folders that belong to an asmdef apply to all the code that uses that asmdef.

This is only if the .dll is in the subfolder of a folder with an asmdef file, not just normally. Mine isn’t.

Well, the part where the analyzer dll is not what needs to be referenced in an asmdef still applies to your case. Are your analyzers inside a UPM package?

How does it still apply? Surely having it as a precompiled asset is for a completely different purpose than references for analyser scope?
No, they are not inside a UPM package, it just as a loose .dll file as the documentation indicates.

It applies in the sense that Unity doesn’t support applying analyzers by adding them as dll references to asmdefs. If your dlls are configured well, and they arent’ in any folder that belongs to an asmdef, they should automatically apply to any code that doesn’t belong to an asmdef. If you want your analyzer to analyze code that belongs to asmdefs, the dll itself must be inside an asmdef folder, and the asmdef that contains the analyzer must be referenced by any other interested asmdef. I think the documentation explains that better, but that’s the gist.

Actually, according to the docs , your analyzer shouldn’t be analyzing your UPM packages, as those use code with asmdefs. That’s the weirdest part for me.

EDIT
In case there’s any doubt, I’m not coming just from reading the docs; I use custom analyzers and generators myself and they work by putting their dlls inside folders under an asmdef and referencing that asmdef wherever I want the analyzers to apply.

Thanks so much for your help! Unfortunately this hasn’t worked for me though. Adding the .asmdef file stopped all the errors from appearing, but adding this .asmdef as a assembly reference in the assemblies of the folders I want to analyze hasn’t applied the analysis to those scripts.

I even have a test script in the same folder as the analyzer, and that isn’t getting analyzed either.

I’m happy to help. :slight_smile:

Here’s the inspector for a generator I’m using right now. Maybe it could help you notice something missing in the config for your dll. Make sure to change something on your test script if you change something in the dll’s importer so that it is reloaded by unity.

If there doesn’t seem to be anything wrong with the dll’s config and your test script is still not being analyzed, I’d recommend reporting a bug to Unity.

The only other thing I could think to check is that my .asmdef files are set up properly. Would u mind sending a screenshot of the .asmdef for the analyser and/or one that references it? Thanks for your help

In the project I have opened right now, I have a couple generators that apply to multiple different asmdfs, with different configurations. The asmdf that owns those generators is a very plain one. It has no references to other assembly definitions, it has the autoreferenced checkmark on, and it applies to Any Platform.

I don’t think it would be the asmdf thing because even if there was a problem with references, the analyzer should at least apply to your test script. That really makes it sound like a Unity bug to me.

Hmm. One thing that might be worth a try is to go to Preferences, click on the External Tools tab, and click the Regenerate project files button. And maybe then make a change in your Test Script, or reimport it, for good measure.

I have reported as a bug! Thanks for your help!

1 Like