As I understand it there are two ways to distribute and consume roslyn analyzers:-
- As a Visual Studio plugin
- As a Nuget package
I frequently find myself wanting to enforce certain domain-specific restrictions, along with convenient code-fixes. (For example, "We need Entity Framework lazy-loading, and so every navigation property in the WidgetFrobber.EntityFrameworkEntities namespace should be virtual.")
It's trivial to write a tiny analyzer that fails the build if someone on my team accidentally writes public ICollection<Widget>
instead of public virtual ICollection<Widget>
, but since this hypothetical analyzer isn't intended to be shared beyond my team (or, in fact, beyond the .sln it's defined in) I'd rather do without distributing a plugin or updating a nuget package whenever I update the analyzer.
References -> Add Reference -> Project
lets me reference the analyzer's types, but doesn't actually add it as an analyzer.References -> Analyzers -> Add Analyzer -> Browse...
expects a .dll rather than a project reference.
Is it possible to reference a Roslyn analyzer inside the .sln that defines it, in the same way that I can reference another project?