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

StyleCop property location inside a file

Is there a way to set StyleCop analyzer to use allow properties to be before constructors in a file. From this class MyClass { public MyClass() { } public int MyProperty { get; set; } } To this class MyClass { public int…
Filip Cordas
  • 2,531
  • 1
  • 12
  • 23
0
votes
0 answers

Roslyn msWorkspace.OpenSolutionAsync() doesn't opens website projects

I have a solution named RoslynTesting.sln has 2 projects (class library and a website) var msWorkspace = MSBuildWorkspace.Create(); var solution = await…
Gifty
  • 185
  • 1
  • 2
  • 16
0
votes
0 answers

How to get SyntaxNode content if it is a method and implemented outside current SyntaxTree?

I am trying to get "content" (SyntaxNodes) of a method when all I have is a SyntaxNode and SyntaxNodeAnalysisContext received by RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression). Method (SyntaxNode) implementation is in another…
Dmitry
  • 421
  • 4
  • 14
0
votes
0 answers

C#, Replacing specific function calls with constants, pre or post compilation

I'm working on optimizing some code. We have system where we can retrieve data from file though a function call that takes the object type and the data name, and gives back the constant in question. Something like: float value = GetData(type,…
Mockarutan
  • 442
  • 4
  • 28
0
votes
0 answers

How do I get project's PackageReferences within DiagnosticAnalyzer

subj, I need to validate that some particular attribute usage also requires particular package to be referenced directly. Thus I need to get somehow the list of PackageReferences within DiagnosticAnalyzer. How do I do that?
pamidur
  • 572
  • 4
  • 11
0
votes
1 answer

How to make sure that Roslyn Analyser does not run in some special cases

I have written a code analyzer by using Roslyn APIs. The analyzer search for the hardcoded Urls in the code and fails the compilation of the code. For example: public class{ public static string demo = "https://demo.com"; } My analyser will…
0
votes
1 answer

Roslyn Analyzer to mark return type of property

I'm writing an analyzer for Roslyn that needs to mark the return type of a property. I have it marking the property declaration itself. I've looked through the debugger but I can't find a location that targets the return type token. Example: //…
gregsdennis
  • 7,218
  • 3
  • 38
  • 71
0
votes
0 answers

Get original namespace of class when referenced

So I currently write code analyzer with roslyn for c#, but now I'm stuck. I want to analyze extension methods. It is demanded that the namespace the extension is declared in, equals the namespace of the class passed with the 'this'…
Tom
  • 1
0
votes
0 answers

Roslyn get classes from a DLL and use them along with updated or new classes in Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create

I'm wondering if such a thing is possible. Let's say I have an existing DLL of a few classes, and I want to compile it with either a new class in the existing DLL, or update an existing class. I know that…
John Ernest
  • 785
  • 1
  • 8
  • 20
0
votes
2 answers

Using Microsoft.CodeAnalysis Nuget package causes WACK to fail

I am planning to publish my WPF app in Microsoft Store using Desktop Bridge. App is using .NET Compiler Platform ("Roslyn"). My problem is that the app is currently failing 2 WACK tests. Fail 1: Debug configuration. Error Found: The debug…
kine
  • 1,352
  • 2
  • 12
  • 24
0
votes
1 answer

Roslyn - integrate analyzer into build avoiding double compilation

I'm currently working on a code analyzer using Roslyn. I need to obtain the Semantic model of my solution, which requires a compilation to be made. I want to integrate this analyzer into our build process (we use MSBuild). Currently it will look…
Alex Buyny
  • 3,047
  • 19
  • 25
0
votes
1 answer

How do you programmatically run Static Code Analysis in Visual Studio 2017?

I'm working on a solution to localize legacy applications. I've written a Visual studio add-in using EnvDte that automates the process of setting the "Localizable" flag for every form in the solution to true, which is a critical step for extracting…
0
votes
1 answer

Using Roslyn, how to enumerate members (Namespaces, classes etc) details in Visual Basic Document?

Using Roslyn, the only mechanism for determining members of Visual Basic document appears to be: var members = SyntaxTree.GetRoot().DescendantNodes().Where(node => node is ClassStatementSyntax || node is FunctionAggregationSyntax || …
Joginder S Nahil
  • 791
  • 1
  • 6
  • 17
0
votes
1 answer

Evaluating boolean expression stored in string with Roslyn

Currently I'm doing some integration testing for an app and such cases are stored in a json file, the assert part of the unit test is also stored in that json, so I need to parse that string to boolean or something. I've tried with Roslyn but I…
0
votes
1 answer

Visual Studio 2017 require "this" code analysis rule like SA1101

When using Visual Studio 2017, with roslyn, is there a way to enable requiring the "this" keyword for all calls to methods inside the class, and class variables? I'm trying to accomplish it through the creation of a new ruleset but I'm not sure if…
Josh R
  • 1,970
  • 3
  • 27
  • 45