Search code examples
c#visual-studioroslynvisual-studio-extensions

C# Compiler Extension doesn't show messages on build


I have a DiagnosticAnalyzer subclass that correctly identifies my issues, and shows them in the Errors window in VS. Writing the code fix is next, but I don't foresee any problems with that.

However, when I actually build my application, the warnings and errors I added do not show up. Is this a limitation of diagnostic analyzers? If not, how can I inform Roslyn that I want to see these problems at build time too?


Solution

  • From the docs:

    Roslyn code analyzers can be installed per-project via a NuGet package. Some are also available as a Visual Studio extension, in which case they apply to any solution you open in Visual Studio. There are some key behavior differences between these two methods of installing analyzers.

    Scope

    If you install analyzers as a Visual Studio extension, they apply at the solution level and to all instances of Visual Studio. If you install the analyzers as a NuGet package, which is the preferred method, they apply only to the project where the NuGet package was installed. In team environments, analyzers installed as NuGet packages are in scope for all developers that work on that project.

    Build errors

    To have rules enforced at build time, including through the command line or as part of a continuous integration (CI) build, install the analyzers as a NuGet package. Analyzer warnings and errors don't show up in the build report if you install the analyzers as an extension.