roslyn

How to get solution path in .NET code analyzer

流过昼夜 提交于 2019-12-01 01:07:57
问题 How do you get access the file path to the project/solution being compiled inside a Roslyn code analyzer? I need to verify the code against some spec files stored relative to the code. Things that do NOT work: SyntaxTreeAnalysisContext.Tree.FilePath Assembly.GetExecutingAssembly().Location AppDomain.CurrentDomain.BaseDirectory Environment.CurrentDirectory Path.GetFullPath(relativePath) 回答1: Analyzers exist below the Workspace level (they're run directly by the compiler), so the solution may

List of breaking changes in Roslyn

回眸只為那壹抹淺笑 提交于 2019-12-01 00:08:40
After switching to Visual Studio 2015, we have noticed that some changes made to how lambdas are compiled to MSIL in Roslyn (described in this thread and on GitHub ) introduce runtime failures under certain conditions. Since Roslyn is obviously the future of .NET, we would like to switch to this technology, but it seems that all legacy code which has been running in production (and where we have a fair degree of confidence it works correctly) is now prone to new runtime failures. These are several libraries which are impacted by this issue also (like Moq, for example ). We already skipped the

How can I resolve all references with Roslyn's OpenSolutionAsync?

久未见 提交于 2019-11-30 21:24:35
I'm trying to open RoslynLight.sln with OpenSolutionAsync then iterate through all the projects. For my purposes I need a semantic model and resolved references. Through a combination of this issue and this question , I've arrived at this partial solution: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.MSBuild; using System.IO; namespace OpenRoslyn { class Program { static void Main(string[] args) { var msbw = MSBuildWorkspace.Create(); var sln = msbw

Getting type from a symbol in roslyn

丶灬走出姿态 提交于 2019-11-30 20:11:41
What is the best general purpose way to get a System.Type from Microsoft.CodeAnalysis.ISymbol for different types of symbols ? (e.g. class declarations, variable, properties, etc) I want to be able to do various checks on the type e.g. as checking if the type implements any interface or is cast-able to any interface, just like one can check on System.Type. The problem I am having is that most of the concrete classes used to represent the symbol are internal (see http://source.roslyn.io/ ) and I could not find tye type information in the ISymbol. SourceNamedTypeSymbol LocalSymbol I retrieve the

Using Roslyn compiler with Visual Studio 2013

≡放荡痞女 提交于 2019-11-30 18:11:25
Is there a way to use the Roslyn compiler with Visual Studio 2013 so that I can take advantage of the new C# 6 features ? Note: Using VS 2015 is not an option. Yes , you can compile C# 6 code with Visual Studio 2013. You just have to install the Microsoft.Net.Compilers NuGet package and your code will build just fine (however, note that you need to target .NET 4.5+). But , the IDE won't understand it. You'll get squiggles everywhere you try to use a C# 6 feature, because VS2013's internal "live" compiler is not the same. Working in such an environment on a daily basis will drive you insane in

Type or namespace not found “are you missing assembly reference” while all references are correct

南楼画角 提交于 2019-11-30 17:50:52
I am trying to use MSBuildWorkspace class . I have all assembly references in my project. When I open the reference in object browser, I see the namespace and the class I am trying to use. But in my following using statement, using Microsoft.CodeAnalysis.MSBuild I am getting a The type or namespace name 'MSBuild' does not exist in the namespace 'Microsoft.CodeAnalysis' (are you missing an assembly reference?) But funny that Syntax highlighter recognizes the type name, its the compiler complaining Here is the build log 1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets

How do I declare a var variable with Roslyn?

我的梦境 提交于 2019-11-30 17:34:24
I've got the following piece of code, but I can't find how to get the var TypeSyntax . Any ideas? Syntax.LocalDeclarationStatement( declaration: Syntax.VariableDeclaration( type: Syntax.PredefinedType(Syntax.Token(SyntaxKind.VarKeyword)), variables: Syntax.SeparatedList( Syntax.VariableDeclarator( identifier: Syntax.Identifier(name))) ) ) ); this fails with an Argument exception that says: "keyword" I'd use: Syntax.LocalDeclarationStatement( declaration: Syntax.VariableDeclaration( type: Syntax.IdentifierName(Syntax.Token(SyntaxKind.VarKeyword)), variables: Syntax.SeparatedList( Syntax

Roslyn has no reference to System.Runtime

陌路散爱 提交于 2019-11-30 17:08:07
I'm working on a project where we are using Roslyn to compile some templates for us. Now when I'm compiling the template I'm receiving multiple errors in the CompileResult.Diagnostics . The errors are: (21,6): error CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (21,6): error CS0012: The type 'System.Type' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture

Show <returns> xml tag into visual studio intellisense

我们两清 提交于 2019-11-30 16:58:22
I added the <returns> xml tag to some of my methods but I can't see its content in IntelliSense. Here is my code: /// <summary> /// we all live in a yellow summary /// </summary> /// <returns>what it returns</returns> public int MyMethod() { .... } Is there any way to show this content? This currently does not work (Visual Studio 2017), and is an open issue: https://github.com/dotnet/roslyn/issues/31618 One way to make it work is to install the ReSharper Visual Studio plugin (but this is paid-for). Sometimes it takes time for the IntelliSense to comprehend your code. To verify that the tag is

Roslyn has no reference to System.Runtime

℡╲_俬逩灬. 提交于 2019-11-30 16:26:23
问题 I'm working on a project where we are using Roslyn to compile some templates for us. Now when I'm compiling the template I'm receiving multiple errors in the CompileResult.Diagnostics . The errors are: (21,6): error CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (21,6): error CS0012: The type 'System.Type' is defined in an assembly