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

OutKind.ConsoleApplication Err(Roslyn Compiler)

I compiling with roslyn some Diagnostics Error showing My code is below: using System; using System.Reflection; using System.Runtime.Loader; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Emit; using System.IO; using…
0
votes
1 answer

How to add custom roslyn analyzer from locally placed DLL?

I have created a Roslyn Analyzer project which generates a nuget package and DLL of it. I want to use that DLL in a standalone code analysis project. How can i do that? For example i have following code: MSBuildLocator.RegisterDefaults(); var…
0
votes
1 answer

Is there a method or a way in Roslyn to enumerate all assemblies used at compile time by a given C# project

I'm developing an application that detects and eliminates useless external references in a given C# project for example a package referenced but not used. For this I need to enumerate all assemblies used either at compile and runtime. For those used…
0
votes
1 answer

Output a Roslyn MSBuildWorkspace to different folder

When executing mSBuildWorkspace.TryApplyChanges(solution); Visual Studio changes the solution in place. This means that if I want to output to a different location, I need to first copy the whole solution to the requested target and only then work…
ispiro
  • 26,556
  • 38
  • 136
  • 291
0
votes
1 answer

SemanticModel GetSymbolInfo().Symbol is Null in Constructed Code but not Parsed Code

Given the following code var forText = "int i;for(i=0;i<3;i++){}"; I wish to grab a reference to the i in i=0, and then request its symbol info to see where it was declared, if anywhere! To do this using the string above, you would do the…
lordmilko
  • 161
  • 1
  • 8
0
votes
0 answers

How to use SyntaxFactory for roslyn

I am trying to generate code using SyntaxFactory but stuck in converting one area Please see the code below I left comment where I am finding it difficult and used string manipulation. The idea is there will be two variable removeExpression and…
user3048027
  • 387
  • 1
  • 5
  • 24
0
votes
1 answer

CodeAnalysis: Loading Linq Assembly

I'm writing an app which uses the Roslyn API to extract information about symbols defined in C# source code files. It does this by compiling the source code in memory and then scanning it. To make that work I have to load the assemblies and nuget…
Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
0
votes
0 answers

Resolving Assembly References in Roslyn

I'm writing a metadata extractor for C# projects. It works by creating SyntaxTrees from source files via CSharpSyntaxTree.ParseText(), compiling them via CSharpCompilation.Create() and then analyzing symbols in the SemanticModel. I'm running into an…
Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
0
votes
1 answer

Determine Needed Assemblies When Compiling C# Project

I am writing a metadata extractor for C# projects. I'm not using MSBuildWorkspace, instead using CSharpSyntaxTree.ParseText() and CSharpCompilation.Create(). Checking the diagnostics from the compilation I noticed that I was missing a number of…
Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
0
votes
2 answers

How to properly use ControlFlowGraph from roslyn code analysis in C#

I cannot understand why I am getting an error (using VS2017) for the code in below related to not finding the class ControlFlowGraph which is supposed to be part of the package Microsoft.CodeAnalysis.FlowAnalysis: using System; using…
0
votes
0 answers

Changing MemberAccessExpression with Rolsyn analyzer

I have a blank Net Core Web project and I want to modify CreateHostBuilder method. I just want to add custom configuration to existing code: IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) …
Kirill Osadchuk
  • 222
  • 2
  • 8
0
votes
0 answers

Project.ProjectReferences shows no item instead of list of project dependencies

I am using the following code to open solution, load the project and create the compilation. var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()); Project valueObjectProject =…
coder
  • 517
  • 5
  • 13
0
votes
1 answer

OpenSolutionAsync crashes with "Illegal characters in path" although the path is legal

I am trying to open a C# solution file with Solution solutionToAnalyze = buildWorkspace.OpenSolutionAsync(pathSolution).Result; and I get the message that I have illegal characters in the path. If I write the path to the Console, it…
0
votes
0 answers

I have a project where I need to read file codes from a .sln source

I don't want to open that (.sln) file in Visual Studio environment I want to use the code in another project for example I have a form where I can select a file (browse) Then select the desired file In a variable! Or even a text file I have the code…
0
votes
1 answer

Roslyn CodeFix with multiple variants to fix

I have a CodeFix provider, purpose of which to inject service to current class, like add new private field, parameter to constructor, assignment statement in constructor, using ServiceNamespace, and use of this field in proper place(s). At some…