Any #DotNet #CSharp #Roslyn experts know what is the cheap/appropriate way to find assembly-level attributes when doing an analysis?

For @xunit we've added some new assembly-level registrations via attribute that would impact whether source analyzers should trigger or not. In this case, we're currently use a mix of SymbolAction and SyntaxNodeAction.

@bradwilson Have your analyzer register a CompliationStartAction, which gives you the compilation. You can get the attributes for the compilation to check for what you need. Then inside that action, register the Symbol/SyntaxNode actions as needed.
@bradwilson That way you'll do the top-level checks first, and you can register the additional checks after they pass. And to get the assembly-level attributes, compilation.Assembly.GetAttributes()
@jasonmalinowski I do have one question, though: how does the analyzer react to attributes coming or going as the source is edited? Should I be calling GetAttributes() from the CompilationStartAction callback or from the SymbolAction/SyntaxNodeAction callback? (This is another way of saying that I'm concerned about caching the results inappropriately because I pulled them at the wrong time)
@bradwilson Any change will cause us to re-run the CompilationStartAction callback. And since I didn't quite make it clear; you can use the context given in the compilation start action to register further things. For example: https://github.com/dotnet/roslyn-analyzers/blob/d6e7d82e631f0b4c2519284a1c12ed9eb945a388/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Tasks/UseValueTasksCorrectly.cs#L93 See how this is checking for some types to exist, and only if it does, it registers something further against the compilation context.
roslyn-analyzers/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Tasks/UseValueTasksCorrectly.cs at d6e7d82e631f0b4c2519284a1c12ed9eb945a388 · dotnet/roslyn-analyzers

Contribute to dotnet/roslyn-analyzers development by creating an account on GitHub.

GitHub
@jasonmalinowski Right, understood. In my case the attributes will just contribute additional context to an analyzer that will always exist ("what's serializable?", effectively). Thanks!
@jasonmalinowski I am already using CompilationStartAction so this should be perfect. Thanks!