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
1
vote
0 answers

Which action should i register in Roslyn to catch ObjectCreation?

Which action should i register in Roslyn to catch ObjectCreation ? I want to catch if coder creates SqlCommand object to do some sql stuff. P.S. I am new with Roslyn, please be patient i am learning and will be better.
Caner Ozden
  • 125
  • 1
  • 4
1
vote
0 answers

Can roslyn syntax tree be converted to xml file?

Syntax visualizer is really good for understanding the code. Bu i want to see the syntax tree in an xml file. Is there any solution for visualizing it by xml ?
Caner Ozden
  • 125
  • 1
  • 4
1
vote
2 answers

Get Build Action from Roslyn API?

Using the Roslyn (Microsoft.CodeAnalysis) APIs, how do I get the Build Action and Copy to Output Directory File Properties? I'm able to open the project file and get the documents, but not sure how to get the file properties. Opening the project…
Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70
1
vote
1 answer

How to use Roslyn Code Analysis API with MVC 6 projects

I intend to use the new Roslyn Code Analysis API with an MVC 6 project. However, when I run this code: string pathToSolution = @"..\..\..\WebApplicationComplex.sln"; const string projectName = "RoslynWebAPIProject"; MSBuildWorkspace workspace =…
Nestor
  • 8,194
  • 7
  • 77
  • 156
1
vote
1 answer

Roslyn: Access XAML of a partial class from code analyzer

The context: we are currently using a solution where all localizable strings are in XAML files which are translated. For translating strings in code, we use a function that will search from associated resource…
0
votes
0 answers

Roslyn semantic model GetTypeInfo on method invoke argument is null

I'm trying to analyze something like blah.SomeMethod(x => x.PropertyA) in a method call and get the class of 'x' and property referenced so I can go verify that property has an expected attribute attached. I want to analyze the first argument to…
Chris Bordeman
  • 255
  • 7
  • 19
0
votes
0 answers

How to use the OpenAIClient in a Roslyn Analyzer without DiagnosticScopeFactory blocking it?

Im trying to write a Roslyn Analyzer which searches in code comments for some kind of hashtags and generates a Gpt prompt from it using the codefix lightbulb. However when sending the gpt request I get an exception stating Message:  Test method…
ChopSeo
  • 1
  • 1
0
votes
0 answers

Finding all cases where Project A references Project B with Roslyn?

Suppose I have 100 classes in Project A, and 50 of them reference classes in Project B. Is there a way to ask Roslyn to find a list of all these 50 classes? Or am I forced to load every class in Project B as a symbol and call…
FBryant87
  • 4,273
  • 2
  • 44
  • 72
0
votes
2 answers

How to get directly referenced projects in a Roslyn analyzer?

I have some C# projects that should have some configurations in the project that references them. I'd like to write a Roslyn analyzer(DiagnosticAnalyzer) to check if those directly referenced projects are configured. "directly referenced" means the…
WAKU
  • 290
  • 3
  • 17
0
votes
1 answer

IMethodSymbol.ReturnType is null and parameters are null

So I have this function which is just a test function and doesn't really do much: public static Task Method(bool b, bool b2, bool b3, bool b4, int i) { Console.WriteLine(b); Console.WriteLine(b2); Console.WriteLine(b3); …
0
votes
0 answers

Resolve project and package references for Rosyln Analyser build

I am building a Roslyn Code Generator and one of the constraints of these analyser-style projects is that they must include all their dependencies in the package; there can be no NuGet dependencies on the package. My generator project has a…
Paul Turner
  • 38,949
  • 15
  • 102
  • 166
0
votes
0 answers

How do code analysis, AST generation and SARIF report work in MSBuild?

Recently, I became curios about mechanism of code analysis in MSBuild. I searched a lot, specially in MSDN but could not get a firm grasp on how exactly this process is done. I want to know what components or classes, in what order, are responsible…
0
votes
0 answers

Get non-framework references within CompilationAnalysisContext

I'm trying to make a diagnostic analyzer that ensures that there are no non-framework assemblies referenced within certain projects. So far, I have this: public override void Initialize(AnalysisContext context) { …
ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81
0
votes
1 answer

Visual Studio: Prevent CodeAnalysis from running on cs files included via nuget

I'm referencing the BlingFireNuget package in my csproj. It adds a bunch of files to my project, including a couple cs files, like BlingFireUtils.cs. These are adding hundreds of code analysis warnings when I build: There must be some way to…
UnionP
  • 1,251
  • 13
  • 26
0
votes
0 answers

How can I get the NUnit CodeFixVerifier to correctly test winforms code?

I am writing a Roslyn analyzer which must (unfortunately) do some analysis on code using winforms. I am having trouble writing unit tests for this analyzer because I cannot get the test state to include the appropriate references or project…