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.

593 questions
33
votes
2 answers

Enabling Microsoft's Code Analysis on .NET Core Projects

Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments. However, now as we create a new .NET Core project, it doesn't look like Code Analysis is a…
StriplingWarrior
  • 135,113
  • 24
  • 223
  • 283
28
votes
5 answers

VS Project References Broken On Case Sensitivity of GUID

Since upgrading to VS 2015, my team has experienced random quirky things which I'm sure are being worked out at Microsoft right now. One pretty annoying one is that we seem to lose project references, especially after branching. I began to work on…
21
votes
7 answers

CSharpAddImportCodeFixProvider encountered an error and has been disabled

I had my PC re-imaged for me. I have Visual Studio Version 14.0.25123.00 Update 2 installed on my computer. I'm getting this error when I try to use VS intellisense to reference another project. CSharpAddImportCodeFixProvider encountered an error…
EGN
  • 2,039
  • 4
  • 23
  • 37
18
votes
3 answers

How can I configure Roslyn Analyzers in many projects?

I want to enforce code quality and consistent styling in my organization. To do this I plan to add Roslyn Analyzers and StyleCop to my projects. In order to meet with our agreed coding standards, these analyzers will need additional configuration.…
Jodrell
  • 31,518
  • 3
  • 75
  • 114
15
votes
1 answer

When to use SemanticModel.GetSymbolInfo and when SemanticModel.GetDeclaredSymbol

In some cases, when I'm trying to get the the ISymbol for my syntax node, I'm fail (getting null) when using SemanticModel.GetSymbolInfo but succeed when using SemanticModel.GetDeclaredSymbol. I've attached an example bellow. So my question is when…
Eli Dagan
  • 738
  • 6
  • 13
12
votes
2 answers

What Replaces Code Analysis in Visual Studio 2019?

I'm toying with getting our team and projects ready for VS 2019. Right away, trying to set up Code Analysis for a new project, I find this: So, if this is deprecated (and apparently can't even be used, so I'm thinking "deprecated" really means…
12
votes
2 answers

Roslyn code analyzers - when should I use "this."?

I've always been explicit with my code when using instance members, prefixing them with this. and with static members, prefixing them with the type name. Roslyn seems not to like this, and politely suggests that you can omit this. and Type. from…
Matthew Layton
  • 32,574
  • 37
  • 140
  • 255
11
votes
2 answers

Getting type from a symbol in roslyn

What is the best general purpose way to get a System.Type from Microsoft.CodeAnalysis.ISymbol for different types of symbols ? (e.g. class declarations, variable, properties, etc) I want to be able to do various checks on the type e.g. as checking…
10
votes
4 answers

"Analyzer with Code Fix" project template is broken

Short question: How to setup a roslyn code analyzer project with a working unit-test project in Visual Studio 2019 v16.6.2? A few months (and a few Visual Studio updates) ago I experimented with setting up a code analyzer project using the "Analyzer…
René Vogt
  • 40,163
  • 14
  • 65
  • 85
10
votes
0 answers

Running DotNet Build Causes Microsoft.Build.Tasks.CodeAnalysis.dll Assembly Conflict

I'm having an issue trying to build a dotnet core project from command line that has these references:
9
votes
1 answer

Confused over ruleset files vs editorconfig files

Our organisation uses a ruleset file containing our organisation's StyleCop.Analyzers settings. This lives in source control, and all projects in all solutions in our organisation reference this file. If I edit the ruleset (via project properties ->…
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
  • 615
  • 7
  • 15
9
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
  • 900
  • 4
  • 20
9
votes
1 answer

How to create an AttributeSyntax with a parameter

I'm trying to use Roslyn to create a parameter that looks something like this: [MyAttribute("some_param")] Now I can easily create the AttributeSyntax but can't figure out how to add an argument to the ArgumentList porperty using the…
devlife
  • 13,287
  • 23
  • 70
  • 126
9
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,591
  • 2
  • 22
  • 31
1
2 3
39 40