To clarify: I'm using Visual Studio 2013 Ultimate, Update 2
I'm trying to create a diagnostic analyzer using Roslyn.
The sample code for a diagnostic analyzer (located here declares such an analyzer in this way:
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class DiagnosticAnalyzer : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer
However when I try to recreate this I cannot find the class DiagnosticAnalyzer
in Microsoft.CodeAnalysis.Diagnostics
(however IDiagnosticAnalyzer
does exist in the same namespace).
Some samples here on StackOverflow instead use (such as this one)
[DiagnosticAnalyzer]
[ExportDiagnosticAnalyzer(DiagnosticId, LanguageNames.CSharp)]
internal class DiagnosticAnalyzer : ISyntaxTreeAnalyzer
However in this case I cannot find the ExportDiagnosticAnalyzer
attribute. It seems I'm missing an assembly. Using NuGet I have installed the following packages:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.Immutable" version="1.1.20-beta" targetFramework="net45" />
<package id="Microsoft.Bcl.Metadata" version="1.0.12-alpha" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Common" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.VisualBasic" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.VisualBasic.Workspaces" version="0.7.4091001-beta" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="0.7.4091001-beta" targetFramework="net45" />
</packages>
Which as far as I could find, also by inspecting packages.config
from the samples, should be everything I need.
When I inspect my C# project's references I have referenced the following non-standard assemblies:
- Microsoft.CodeAnalysis
- Microsoft.CodeAnalysis.CSharp
- Microsoft.CodeAnalysis.CSharp.Desktop
- Microsoft.CodeAnalysis.CSharp.Workspaces
- Microsoft.CodeAnalysis.Desktop
- Microsoft.CodeAnalysisWorkspaces
- Microsoft.CSharp
My question is, what am I missing that I can't find all the classes I need to create a diagnostic analyzer?