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
0
votes
1 answer

Inspecting constructor chain via Roslyn

Say I have a base class B and a derived EB class. How can I check which base constructor each EB's constructor calls? Is it possible to do that via semantic model? The code that illustrates my attempt is as follows: var typeSymbol =…
user3284063
  • 665
  • 5
  • 20
0
votes
2 answers

Compile to module with Roslyn

I need to compile any C# or VB.NET project to .NetModule. I have following sample code which emits DLLs, Need some help to modify following to get .NetModules out from .csproj Thanks in advance. // Required Microsoft.CodeAnalysis 1.3.0 class…
Bandara
  • 780
  • 8
  • 29
0
votes
0 answers

Get rid of stylecop.json from nuget package

I've setup building nuget package from my project using package tab in project options. Everything seems to work except that my nuget package contains stylecop.json file. Build action for this file is set to "C# analyzer additional file". How to get…
0
votes
1 answer

VS 2017 - DotNetAnalyzers Warnings Showing Up in Build Output, But Not Code Analysis

I'm seeing the following in VS 2017 Enterprise on a csproj, Project1, that's being built on .Net 4.5.2: 18>------ Rebuild All started: Project: Project1, Configuration: Debug Any CPU ------ 18>C:\git\27844-2-StyleCop\company\Class1.cs(26,31,26,47):…
0
votes
1 answer

Roslyn - get interfaces of a referenced dll

I would like to analyze a specific class in a given Visual Studio solution, using Roslyn. During this analysis I would like to get all the Interfaces that the class is using. I've seen several examples in which it's possible to retrieve the…
Ofer
  • 31
  • 7
0
votes
1 answer

How to find nodes before a given node with Roslyn?

I am developing a Roslyn analyzer to detect the use of a specific method, method1. I want to allow the use of this method in for and while loops, and create an issue in all other cases in the code. How can I do that? The code I developed detects…
Samorix
  • 307
  • 4
  • 17
0
votes
1 answer

Check whether method body conains ViewResult returns

I'm trying to fix this issue https://github.com/dotnet-security-guard/roslyn-security-guard/issues/60 Affected file is…
Andrii
  • 1,081
  • 1
  • 11
  • 24
0
votes
1 answer

Is it possible to create an attribute that will break the build under a condition?

It seemed like this was possible, but I can't find a reference on how to accomplish it, though I've seen a few things that are closely related. I have a particular type of class that requires a public or private default ctor. The reason is…
Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
0
votes
1 answer

Roslyn compilation cannot resolve com reference in unit test

I have written a unit test that compiles an external solution. One of the projects in this solution has a COM reference (SHDocVW). When Roslyn tries to compile this project, it gives a compilation error that it cannot resolve this reference. When I…
0
votes
1 answer

How do I get a IMethodSymbol or the syntax node of the method declaration from a InvocationExpressionSyntax node which calls the method?

In the implementation of my analyzer I am in the AnalyzeSymbol method: public override void Initialize(AnalysisContext context) { context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method); } private static void…
David
  • 2,426
  • 3
  • 24
  • 36
0
votes
1 answer

Create a method call analyzer with Roslyn

I need to parse a .cs file to look for a particular method. For instance, once the method named "X" is called, the analyzer should detect it. How can detect that this particular node is a method? Thanks in advance!
Samorix
  • 307
  • 4
  • 17
0
votes
0 answers

Compatibility between Roslyn API and .netCore applications

I try to create application responsible for analysing existing dll and generating output code based on this one. I created .netCore console application as entry point and several .netCore class libraries which incapsulating analysis and generating…
paranamix2
  • 337
  • 2
  • 17
0
votes
1 answer

How to create a compilation unit from an AST

I am writing a solution which requires an AST to be generated and then this AST should be parsed in order to generate a valid compilation unit with semantics available. The AST is generated by means of SyntaxFactory class. Then I will need to get a…
Andry
  • 16,172
  • 27
  • 138
  • 246
0
votes
1 answer

Determining if the current span is an attribute deleration using Roslyn APIs

I'm building a visual studio extension for coloring various language constructs using Roslyn APIs, I want to change the color of attribute declarations, like Asp.Net MVC [Require] attribute for example. I have access to SyntaxNode and ISymbol, my…
Hamid Mosalla
  • 3,279
  • 2
  • 28
  • 51
0
votes
1 answer

SyntaxGenerator.IdentifierName escapes minimally qualified primitive types

When I try to create an identifier using the Roslyn SyntaxGenerator.IdentifierName for a primitive type, it adds an escape to the Identifier.Text. var generator = SyntaxGenerator.GetGenerator(document); // genericTypeArg.Identifier.ValueText =…