Roslyn has banned analyzers feature. I want to use in my own code that compiles code dynamically (own scripting engine based on C# lang) via CSharpCompilation class with WithAnalyzers extension method.
I tried to add the package reference on nuget — Microsoft.CodeAnalysis.BannedApiAnalyzers , but the package cannot use as a regular nuget package. Class CSharpSymbolIsBannedAnalyzer marked as unknown.
My code:
var compilation = CSharpCompilation.Create(/* made syntax tree + dll refs */);
var analyzers = ImmutableArray.Create<DiagnosticAnalyzer>(
new CSharpSymbolIsBannedAnalyzer()); // <- unknown type
var compilationWithAnalyzers = compilation.WithAnalyzers(
analyzers,
new AnalyzerOptions(ImmutableArray.Create<AdditionalText>(new BannedSymbolsAdditionalText(@"T:System.Diagnostics.Process;Don't use Process"))),
cancellationToken);
But when I try to compile, I get:
CSharpSymbolIsBannedAnalyzer is unknown type.
usingdirective, didn't you?