Search code examples
visual-studio.net-standardmicrosoft.codeanalysis

DiagnosticAnalyzer from same solution by reference


I have a DiagnosticAnalyzer and a CodeFixProvider in a class library, In other words a Roslyn Analyzer. I can Nuget package or Vsix package it but I never plan to publish it and I only need to use it in an single mono solution. I was hoping that simply adding the class library as a reference would treat the class library as an "Analyzer" like it would being Nuget installed but it doesn't. Is it possible to use the DiagnosticAnalyzer from the same solution?


Solution

  • You can add an analyzer by referencing a dll, which should work with one you've built yourself.

    • Navigate to project
    • Expand References
    • Right-click Analyzers
    • Select Add Analyzer...
    • Select Browse... and navigate to the dll

    Related Question

    Screenshot of Add Analyzer


    Edit: For .NET Core and .NET Standard projects that don't have tooling as stated here manually add this snippet to your .csproj

    <ItemGroup>
      <Analyzer Include="path\to\Analyzer.dll" />
    </ItemGroup>