13

I want to write a custom code analyzer in Visual Studio 2015 for a C# ConsoleApplication. For this reason I don't want to create a seperate "Analyzer with Code Fix" project from template, because this requires to add this analyzer in my projects as nuget package.

enter image description here
Is it possible, to add a analyzer reference manually? I would like to reference the analyzer without nuget.

svick
  • 236,525
  • 50
  • 385
  • 514
Michi-2142
  • 1,170
  • 3
  • 18
  • 39

2 Answers2

11

If you add an analyzer as Nuget and check the content of your project, you'll see that only an <Analyzer Include="..." /> item is added. You can do the same manually. Also, you can do this in the .csproj.user file as well, so you can also do it locally, and not commit this change to your SCM.

Tamas
  • 6,260
  • 19
  • 30
  • 2
    I've found in VS2017 at least that if you just add an tag to your project, you only get warnings when you build, not as you type. You seem to need to have the nuget package in the packages.config and the tag to get the warnings both when you're editing code and compiling. – John Hall Oct 25 '18 at 10:59
  • 1
    I only get " – zezba9000 Mar 08 '19 at 08:52
  • Beware that `` requires a path to an assembly, and won't work with csproj – Métoule Jun 16 '23 at 09:48
3

You can add analyzer via project reference with OutputItemType set to Analyzer:

<ItemGroup>
  <ProjectReference Include="..\Analyzers\Analyzers.csproj">
     <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     <OutputItemType>Analyzer</OutputItemType>
   </ProjectReference>
</ItemGroup>
Guru Stron
  • 102,774
  • 10
  • 95
  • 132