roslyn-code-analysis

Exception line number in CSharpScript.EvaluateAsync

末鹿安然 提交于 2019-12-23 17:23:55
问题 I'm evaluating an script using the CSharpScript.EvaluatyAsync<T> method and passing some C# code. I can easily see the line number of errors when there is a parsing issue, e.g. a syntax error, but when there is a runtime exception all I get is an AggregateException wrapping my exception ( NullReferenceException ) in this case, but there is no clue of how to get the line number for me (3 in this example below). Console.WriteLine(CSharpScript.EvaluateAsync<int>( @"string s = null; // some

Appveyor nuget analyser

泪湿孤枕 提交于 2019-12-23 08:58:53
问题 I'm trying to invent good way to pack my Roslyn analyzer projects into NuGet. It requires specific NuGet package structure with .dll put into \analyzer\ , not \lib\ . For this to work, I have to call nuget pack <name>.nuspec , not nuget pack <name>.csproj . But if I use nuspec , than $version$ tag gets ignored. Seems that my only option is to manually update version in .nuspec on every rebuild. What is correct and right way to accomplish this? 回答1: I just had the same problem. I don't like

Doesn't Visual Studio 2015 Community edition support live code analyzer?

坚强是说给别人听的谎言 提交于 2019-12-23 05:26:31
问题 I have a Visual Studio 2015 professional (in Windows 7) and Visual Studio 2015 community (in Windows 10), both of have latest update 1 installed. And I have both of them opened the exactly same solution. Both tools also have Refactoring Essentials for Visual Studio plug-in installed. In professional edition I can clearly see live code analyzer actually works: You can see the wave lines under files, folders, projects and solution. When I hover mouse over then I can preview the issue before I

Opening a solution with msbuildworkspace gives diagnostics errors without details

*爱你&永不变心* 提交于 2019-12-22 11:18:44
问题 I am trying to analyse a solution with Roslyn, with MSBuildWorkspace. The solution is a new solution, with 2 class library projects in them, one referencing the other. They are created in Visual Studio 2017, .Net 4.6.2. When I open the solution, I receive two generic errors in workspace.Diagnostics, both are : Msbuild failed when processing the file ' PathToProject ' There is nothing more in the diagnostics or output window, to indicate WHY it failed to process the project file. The code for

Is it possible to use Rosyln or Resharper to detect possible DivideByZero cases?

北城余情 提交于 2019-12-22 08:35:12
问题 I'm trying to determine if there's a programmatic way to check for possible DivideByZeroException in my codebase. My codebase includes a series of relatively simple to relatively complex formulas, approximately 1500 of them (and growing). When new formulas are written, care must be taken to ensure that division is done safely to avoid exceptions during processing of these formulas. E.g. decimal val1 = 1.1m; decimal val2 = 0m; var res = val1/val2; //bad var res = val2 == 0 ? 0 : val1/val2; /

How do I get a IMethodSymbol or the syntax node of the method declaration from a InvocationExpressionSyntax node which calls the method?

孤街浪徒 提交于 2019-12-22 00:28:12
问题 In the implementation of my analyzer I am in the AnalyzeSymbol method: public override void Initialize(AnalysisContext context) { context.RegisterSymbolAction(AnalyzeSymbol, SymbolKind.Method); } private static void AnalyzeSymbol(SymbolAnalysisContext context) { // here I look through the syntax of the method body in order to find invocations. var methodSymbol = context.Symbol as IMethodSymbol; var location = methodSymbol.Locations.FirstOrDefault(); var methodNode = location.SourceTree

Roslyn add new method to an existing class

这一生的挚爱 提交于 2019-12-21 17:02:15
问题 I'm investigating the use of the Roslyn compiler within a Visual Studio Extension (VSIX) that uses the VisualStudioWorkspace to update existing code. Having spent the last few days reading up on this, there seem to be several ways to achieve this....I'm just not sure which is the best approach for me. Okay, so let's assume that the User has their solution open in Visual Studio 2015. They click on my Extension and (via a form) they tell me that they want to add the following method definition

Enabling Microsoft's Code Analysis on .NET Core Projects

情到浓时终转凉″ 提交于 2019-12-18 11:46:28
问题 Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments. However, now as we create a new .NET Core project, it doesn't look like Code Analysis is a feature of these new projects. There is no UI for it in the Project Properties area, and adding a custom ruleset to the project as recommended here only appears to affect StyleCop Analyzers (the SAxxxx rules). Is there any way to enable Code Analysis (

How to compare type symbols (ITypeSymbol) from different projects in Roslyn?

左心房为你撑大大i 提交于 2019-12-12 12:28:41
问题 I have 2 test projects in solution. First project ("VDoc") declare VDocQuery type. Second project ("VDocQueryTest" ) calls VDocQuery constructor. I get 2 VDocQuery's ITypeSymbol's (one from each project), compare it, but get false result. Steps: 1. Get first ITypeSymbol (from VDoc project with SemanticModel.LookupNamespacesAndTypes() method). 2. Get second ITypeSymbol from VDocQueryTest project (from ObjectCreationExpressionSyntax.GetTypeInfo().Type) 3. Compare it with ITypeSymbol.Equals

How to use Roslyn Code Analysis API with MVC 6 projects

流过昼夜 提交于 2019-12-11 10:55:12
问题 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 = MSBuildWorkspace.Create(); Solution solutionToAnalyze = workspace.OpenSolutionAsync(pathToSolution).Result; Project sampleProjectToAnalyze = solutionToAnalyze.Projects.Where((proj) => proj.Name == projectName).FirstOrDefault(); Compilation