roslyn-sdk
roslyn-sdk copied to clipboard
Project > Add > New Item > Analyzer (C#) does not install necessary Nuget packages, resulting in compile errors
Visual Studio Version Used: 16.2.1
Steps to Reproduce:
- Create class library, .net standard, c#
- Right-click new library in solution explorer
- Click New > Add Item > Extensibility > Analyzer
- Click Analyzer
- Press Add 6 Build class library
Expected Behavior: No compile errors
Actual Behavior: Compile Errors:
2>------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
2>Analyzer1.cs(3,26,3,35): error CS0234: The type or namespace name 'Immutable' does not exist in the namespace 'System.Collections' (are you missing an assembly reference?)
2>Analyzer1.cs(6,17,6,29): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2>Analyzer1.cs(7,17,7,29): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2>Analyzer1.cs(8,17,8,29): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2>Analyzer1.cs(9,17,9,29): error CS0234: The type or namespace name 'CodeAnalysis' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
2>Analyzer1.cs(14,30,14,48): error CS0246: The type or namespace name 'DiagnosticAnalyzer' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(23,25,23,61): error CS0246: The type or namespace name 'ImmutableArray<>' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(23,40,23,60): error CS0246: The type or namespace name 'DiagnosticDescriptor' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(13,6,13,24): error CS0246: The type or namespace name 'DiagnosticAnalyzerAttribute' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(13,6,13,24): error CS0246: The type or namespace name 'DiagnosticAnalyzer' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(13,25,13,38): error CS0103: The name 'LanguageNames' does not exist in the current context
2>Analyzer1.cs(25,41,25,56): error CS0246: The type or namespace name 'AnalysisContext' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(23,62,23,82): error CS0115: 'Analyzer1.SupportedDiagnostics': no suitable method found to override
2>Analyzer1.cs(17,34,17,51): error CS0246: The type or namespace name 'LocalizableString' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(18,34,18,51): error CS0246: The type or namespace name 'LocalizableString' could not be found (are you missing a using directive or an assembly reference?)
2>Analyzer1.cs(21,25,21,45): error CS0246: The type or namespace name 'DiagnosticDescriptor' could not be found (are you missing a using directive or an assembly reference?)
I believe step (3) is only really supported if in step (1) the project was created from the Analyzer and Code Fix template. Even if the correct packages were installed, the analyzer item will not be able to perform all the actions necessary to turn an arbitrary library into a testable/distributable analyzer package.
We should look into adding nuget packages if they don't already exist for the item templates. This can be done with a 'wizard' similar to what we used to do for the project templates