Questions tagged [roslyn-code-analysis]

For questions regarding code analysis for C# and VB based on the Roslyn .NET compiler platform API.

The Roslyn compiler platform provides an API to implement code analysis, code fixes, and refactoring tools for C# and VB.

The Roslyn Wiki also contains an introduction for "How To Write a C# Analyzer and Code Fix" and for Visual Basic.

769 questions
11
votes
0 answers

What can I do if a code analyzer rule produces an exception (message AD0001)?

In a sample project, I get the following notification message by the code analzyer: I tried to disable the mentioned rule (CA1033) - but the message persists. As there is no information in which file this exception is created, I've no idea which…
ventiseis
  • 3,029
  • 11
  • 32
  • 49
10
votes
0 answers

Why does my C# analyzer not display messages (DiagnosticSeverity.Info)

Recently started messing around with C# analyzers and generators, and I had to find out that reported diagnostics show up fine when using DiagnosticSeverity.Warning or DiagnosticSeverity.Error, but not at all with DiagnosticSeverity.Info. External…
michi-b
  • 205
  • 1
  • 6
10
votes
1 answer

Make diagnostic errors reported by a C# source generator appear in the Visual Studio editor

I am attempting to write a C# source generator that throws a warning/error under certain conditions using GeneratorExecutionContext.ReportDiagnostic. My source generator is able to run and output errors successfully upon building a sample project…
10
votes
1 answer

Putting files in "analyzer" dir in nupkg using new csproj format

I'm using new .csproj file format to pack NuGet package without using .nuspec file. The problem is, it puts my dll in \lib\ where I need to put it \analyzers\ Who I do accomplish that?
Leotsarev
  • 1,040
  • 7
  • 23
10
votes
1 answer

Roslyn add new method to an existing class

I'm investigating the use of the Roslyn compiler within a Visual Studio Extension (VSIX) that uses the VisualStudioWorkspace to update existing code. Having spent the last few days reading up on this, there seem to be several ways to achieve…
DrGriff
  • 4,394
  • 9
  • 43
  • 92
10
votes
1 answer

Run code analysis tool from command line in VS 2015

I want to run the code code analysis tool provided by VS 2015 from the command line the same way I was able to generate FxCop reports, something like this: FxCopCmd.exe /console /project *Project* /out:*ReportFile* Note that I don't want to use the…
Pinte Dani
  • 1,989
  • 3
  • 28
  • 35
9
votes
1 answer

What are the effects of the "EnforceExtendedAnalyzerRules" flag in the project file

During my work on a Roslyn analyzer I have received an alert from Roslyn analyzer that checks the correct usage of Roslyn API. RS1036: Specify analyzer banned API enforcement setting. A project containing analyzers or source generators should…
SENya
  • 1,083
  • 11
  • 26
9
votes
1 answer

VS 2019 - seeing many warnings AD0001 from Microsoft.CodeAnalysis.CSharp.Analyzers

I get this exact warning many time in the Error List pane in VS 2019 (v16.4.2). How can i resolve the warnings ? AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.FixAnalyzers.CSharpFixerWithFixAllAnalyzer' threw an exception of type…
Menahem
  • 3,974
  • 1
  • 28
  • 43
9
votes
1 answer

How do I check with Roslyn if a Type is a Nullable Reference

I am trying to analyze with roslyn if a type declaration is a "Nullable Reference" type (C#8) I was planing on looking if the TypeSyntex was a NullableTypeSyntax and if the ITypeSymbol.IsReferenceType is true. The following code works for the most…
9
votes
4 answers

How do I specify a custom code analysis ruleset for multiple projects in a solution using Visual Studio 2019?

I've got a custom code analysis ruleset that I want to apply to all configurations of multiple projects in my solution but can't see how I can do it. To be clear, I'm looking for a way (if any) of doing this in a single step rather then editing the…
9
votes
3 answers

How do you disable Roslyn Analyzers when using msbuild through the command line?

The Roslyn Analyzers are installed as nuget packages, which are dependencies of the FxCop Analyzers (also installed as nuget packages). I have enabled full solution analysis as instructed here: How to Enable and disable full solution analysis for…
Rich
  • 1,895
  • 3
  • 26
  • 35
9
votes
1 answer

What's the difference between Microsoft.CodeAnalysis.FxCopAnalyzers and Microsoft.CodeAnalysis?

I want to install code analysis in one of my C# projects, and it seems that the way people add code analysis to .NET Core projects is by using the NuGet package Microsoft.CodeAnalysis.FxCopAnalyzers. However, I also found other NuGet packages from…
Andrej Lucansky
  • 725
  • 10
  • 17
9
votes
1 answer

Get dependencies between classes in Roslyn

I am successfully getting dependencies between projects with Roslyn, and now I would like to get dependencies between classes, similar to the Code Map feature in Visual Studio Enterprise. Here is my code, the "?????" part is where I imagine I could…
heltonbiker
  • 26,657
  • 28
  • 137
  • 252
9
votes
2 answers

How to use Roslyn to get compile time constant value

I have some example code that simplifies want I am trying to accomplish. OptionAtrribute.cs using System; public class OptionAttribute : Attribute { public OptionAttribute(string option) { this.PickedOption = option; } …
jon antoine
  • 396
  • 1
  • 4
  • 16
9
votes
2 answers

Suppressing issues from Roslyn code Analyzers

Is there any way to suppress the issues from the Roslyn Analyzers? I use the instant analyzer project type. And I want to suppress the issues if the user wants it. Also it must be permanent. If I reopen Visual Studio, the same suppression rules must…
Caner Ozden
  • 125
  • 1
  • 4
1
2
3
51 52