Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question StyleCop Roslyn Analyzer and Scope

Discussion in 'Editor & General Support' started by Afropenguinn, Apr 24, 2022.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    So I'm looking to apply the StyleCop Roslyn Analyzer to this folder structure:
    - Assets
    - _Project <- Only here
    - Other Folders​
    '_Project' contains multiple assemblies, and I want all of them to use StyleCop, but nothing outside of the '_Project' folder should use it, so nothing in 'Other Folders' should. I can't seem to get it to stay in scope of that folder only, and without having multiple copies of the analyzer DLL's in the project. Anyone else run into this?
     
  2. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
  3. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Unity supports Roslyn Analyzers, as well as controlling the scope of an analyzer, does it not? Or is it just all or nothing?
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    The author of the tool would likely know! I personally have not used one, just trying to help since no one else has. https://docs.unity3d.com/Manual/roslyn-analyzers.html
     
  7. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    Still haven't found a good solution to this. The idea that somewhere in the project you'd have the ruleset and analyzer dll files, and you'd be able to make assembly definitions opt into it.
     
  8. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    261
    I'm trying to do more complex limitations, like defining which AssemblyDefinitions would be affected by the analyzers since I don't want to analyze code coming from Packages, but no success yet.

    Your case is a bit easier to achieve, but only if you can live with only one Asmdef at the root of '_Project' folder. It would be like that:
    Assets/_Project/YOUR_ANALYZER.dll
    Assets/_Project/YOUR_ASSEMBLY_DEFINITION.asmdef

    With that, the analyzer will affect only the scripts having YOUR_ASSEMBLY_DEFINITION.asmdef as their assembly.

    You can follow my question regarding multiple Asmdef files here:
    https://forum.unity.com/threads/exclude-unityx-packages-from-roslyn-analyzers.1164572/#post-8529479