Questions tagged [microsoft.codeanalysis]

Formerly known as Project roslyn.

see https://www.nuget.org/packages/Microsoft.CodeAnalysis

69 questions
0
votes
0 answers

How to find .ToString() calls on enum values in C#

I am trying to use Roslyn analyzers to find all instances of using .ToString() on an enum value so that I can suggest a codefix to use the nameof() expression instead. How can I go about doing this? I've trudged through it for the string…
Duu82
  • 157
  • 2
  • 11
0
votes
1 answer

Issues with operator resolution in value types (no references added)

I was working on a project and I found that the operator I used and the one I declared were not equal. I made a minimum reproducible example: var tree = CSharpSyntaxTree.ParseText(@" bool a = 3 > 5; namespace System{ public struct Int32 { …
trinalbadger587
  • 1,905
  • 1
  • 18
  • 36
0
votes
0 answers

Microsoft.CodeAnalysis build failing despite project locally running correctly

I am getting an error upon build in Azure DevOps when trying to merge to develop: ##[error]CSC(0,0): Error CS0006: Metadata file '..\packages\Microsoft.CodeAnalysis.Analyzers.1.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll' could not…
0
votes
1 answer

Visual Studio 2019 and ReSharper: deactivate Studio code analysis

I had Studio 2019 Community Edition installed, as well ReSharper. Since we use ReSharper for code analysis, we deactivated Studio code analysis by .editorconfig with only 2 lines: root = true dotnet_analyzer_diagnostic.severity = none Everything…
Mate
  • 241
  • 1
  • 2
  • 11
0
votes
1 answer

Why does few analyzer rules have their effective severity set to suppressed in .NET4.6

After adding code quality NuGet packages, I can see that by default, the effective severity level for some rules is set to suppress. But their default severity level remains warnings. Severity set as suppress not as warning How can I set the…
0
votes
1 answer

Runtime compiling DbContext with EF core, missing reference for Migrator()

I'm building an app that requires a EntityFrameWorkCore DbContext to be created runtime and then migrated, the code below compiles and runs if i don't use the dbContext.Database.Migrate() method, but if i do i get a diagnositcs error about missing a…
0
votes
1 answer

SonarQube doesnt find Microsoft.CodeAnalysis 1.3.1.0 but it is installed

I have tried to run a SonarQube scan on my C# projects. I have 3 projects and 1 solution file. I run: SonarScanner.MSBuild.exe begin /o:"xxxxxxxxx" /k:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /d:sonar.host.url="https://sonarcloud.io"…
Keka Bron
  • 419
  • 4
  • 17
0
votes
1 answer

Roslyn: Reconstruct code from BasicBlocks in a CFG

In Roslyn, a control flow graph has the list of BasicBlocks which constitute the program. Is it possible to get code statements from each block to reconstruct the entire code?
0
votes
1 answer

How to compile in memory and get assembly using Microsoft.CodeAnalysis

Before I was using System.CodeDom.Compiler. It has options that allow compiling in memory and return assembly: var compilerParams = new CompilerParameters { GenerateInMemory = true, GenerateExecutable = false, …
Dilshod K
  • 2,924
  • 1
  • 13
  • 46
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
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
1 answer

Analyze nullability inside anonymous types with Roslyn

Here's a piece of code I want to analyze with Roslyn: object Method() { var rnd = new Random(); return new { First = "1", Second = rnd.NextDouble() > 0.5 ? "2" : null }; } I would like to find out the nullability of the returned properties. I…
jods
  • 4,581
  • 16
  • 20
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