roslyn-code-analysis

EF Core Analyzer RawSqlStringInjectionDiagnosticAnalyzer error

南笙酒味 提交于 2021-01-29 21:25:03
问题 I am trying to port everything from Entity Framework 6.3 to Entity Framework Core 2.1.2 and this is my first experience with EF Core. I have 2 projects one is my core or infrastructure project with all the entity models, DB Context and repositories and the other one is an asp.Net MVC which is my startup project and using all the services from the core project. Both projects are using .NetStandard Library 2.0.3 and targeted .Net Framework 4.6.2. And I have .Net Core SDK 2.2 on my machine. The

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

拈花ヽ惹草 提交于 2020-07-23 06:41:43
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

那年仲夏 提交于 2020-07-23 06:40:33
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

How to show Analyzer errors/warnings during msbuild in VS Dev Cmd & using MSBuildWorkspace

﹥>﹥吖頭↗ 提交于 2020-07-23 06:39:30
问题 I'll explain the situation with an example. Suppose I have created a Roslyn Analyzer which throws Error when Class name is TestClass . Analyzer code is as below: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(Method, SyntaxKind.ClassDeclaration); } private static void Method(SyntaxNodeAnalysisContext context) { var node = (ClassDeclarationSyntax)context.Node; var name = node.TryGetInferredMemberName(); if(name == "TestClass") { context

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

这一生的挚爱 提交于 2020-07-10 07:01:11
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

Roslyn error only with .NET Core: “ResolvePackageFileConflicts” task failed unexpectedly

故事扮演 提交于 2020-07-10 07:00:40
问题 My code is responsible for get types namespaces using Roslyn API based on solution file path; before i find out namespaces, i get the documents with: using (var ws = MSBuildWorkspace.Create()) { var solution = await ws.OpenSolutionAsync(solutionPath); //[...] some code var diagnostics = ws.Diagnostics; //[...] some code return solution.Projects.SelectMany(p => p.Documents); } When i pass as parameter some solution file path from a .NET Framework solution, the code works fine. But when i pass

How to load solution in Roslyn?

人盡茶涼 提交于 2020-05-29 07:47:49
问题 Here is my code that used to work: MSBuildWorkspace msBuild = MSBuildWorkspace.Create(); Solution sln = await msBuild.OpenSolutionAsync(solutionPath); but now I get: int pr = sln.Projects.Count();//is 1 instead of 2. and: int docs = sln.Projects.First().Documents.Count();//is 0 Have they changed it again? (If it matters, I need the Solution in order to iterate over fields etc. and use Renamer.RenameSymbolAsync .) 回答1: The way I did it was like so: if (!MSBuildLocator.IsRegistered)

Resolving Assembly References in Roslyn

落爺英雄遲暮 提交于 2020-03-05 00:31:30
问题 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 issue where various assembly references aren't being handled correctly. I generate assembly references by parsing project.assets.json and extracting the compile-time package references (my test project doesn't include any project references).

Add a parameter to a method with a Roslyn CodeFixProvider

亡梦爱人 提交于 2020-01-23 07:53:13
问题 I'm writing a Roslyn Code Analyzer that I want to identify if an async method does not take a CancellationToken and then suggest a code fix that adds it: //Before Code Fix: public async Task Example(){} //After Code Fix public async Task Example(CancellationToken token){} I've wired up the DiagnosticAnalyzer to correctly report a Diagnostic by inspecting the methodDeclaration.ParameterList.Parameters , but I can't find the Roslyn API for adding a Paramater to the ParameterList inside a

Mark parameters with a [ReadOnly] attribute and let an analyzer assert, that no reassignment is in the method body

断了今生、忘了曾经 提交于 2020-01-17 15:27:29
问题 Not being able to mark a parameter of a method as readonly so that it is impossible to be reassigned in the method, I started thinking abount creating an analyzer for this. The parameter would be attributed with [AttributeUsage(AttributeTargets.Parameter)] public class ReadOnlyAttribute: Attribute { // ... } and the signature of a method would be public class Foo { public void Bar([ReadOnly] MyObject o) { o.DoSomething() // this is OK o = new MyObject() // this would be flagged by the