roslyn

How to get reference to 'Roslyn' Workspace object from IVsSolution?

主宰稳场 提交于 2019-12-17 19:52:53
问题 I have a VS Package project from which I need to access Roslyn or Microsoft.CodeAnalysis' Workspace OR Solution object from the loaded IVsSolution. I need to know how I could achieve that ? I found this stackoverflow discussion here which suggests to use PrimaryWorkspace static property of Workspace class which I can't find in Microsoft.CodeAnalysis.Workspace EDIT: I found out that Microsoft.CodeAnalysis does not have this yet but I downloaded the older release of Roslyn from Nuget.org which

What's the latest version of Roslyn my analyzer can target if I support VS2015?

爱⌒轻易说出口 提交于 2019-12-17 16:39:35
问题 I'm writing a Roslyn diagnostic analyzer that should work on VS2015 and later editions. I want to know the latest version of Microsoft.CodeAnalysis I can use with my project and still support VS2015. I need to use an API that was added in Roslyn 1.2.0 ( AnalysisContext.EnableConcurrentExecution ), but I think that version of Roslyn isn't included with VS2015 (IIRC, only VS2017 supports C# 7). Does this mean I can't use this API in my analyzer? 回答1: Yes, Roslyn 2.3.0 will only work on Visual

What / why is Roslyn “needed” in /bin folder of Asp.Net

假如想象 提交于 2019-12-17 15:53:14
问题 There are a bunch of related questions on this, though most of the answers define Roslyn and/or provide a "fix" to some issue ( exe , with hosting providers, etc.) What I can't seem to track down is the "why" and "what for" (perhaps only in the context of ASP.Net MVC/Web API) in /bin/roslyn . I ran in to similar issues (hosting - .exe restrictions, support for 4.6 , etc.) and my "fix" was to "just deploy to Azure" (of course everything works without a hitch). But really, this doesn't answer:

C# 6.0 TFS Builds

房东的猫 提交于 2019-12-17 09:46:45
问题 I'm trialing the new features of C# 6.0 within Visual Studio 2015 CTP and my project is failing to build in TFS 2013 and Visual Studio Online. I understand that Visual Studio uses the new Roslyn compiler, which replaces the native .NET one, and the TFS build agent therefore is unable to compile. My question is how do I install Roslyn on the build agent (and within Visual Studio Online) and tell the build agent to use this compiler over native? 回答1: For the compilation step, you have a couple

Delegate caching behavior changes in Roslyn

南笙酒味 提交于 2019-12-17 04:32:25
问题 Given the following code: public class C { public void M() { var x = 5; Action<int> action = y => Console.WriteLine(y); } } Using VS2013, .NET 4.5. When looking at the decompiled code, we can see that the compiler is caching the delegate at the call site: public class C { [CompilerGenerated] private static Action<int> CS$<>9__CachedAnonymousMethodDelegate1; public void M() { if (C.CS$<>9__CachedAnonymousMethodDelegate1 == null) { C.CS$<>9__CachedAnonymousMethodDelegate1 = new Action<int>(C.<M

C# 6.0 Features Not Working with Visual Studio 2015

心已入冬 提交于 2019-12-17 02:34:22
问题 I am testing Visual Studio 2015 with C# 6.0 but the language features are not working. In an MVC web application, the following code does compile: if (!string.IsNullOrWhiteSpace(Model.Profile?.TypeName)) { // More logic here... } However, when I run the application via Debug and IIS Express, I get the following error: CS1525: Invalid expression term '.' How do I enable these features? 回答1: This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package CodeDOM

Identify if class is abstract with Roslyn

南笙酒味 提交于 2019-12-14 03:49:47
问题 I've searched here I didn't find the answer here. How can I know if class is a abstract class from a ClassDeclarationSyntax . Here is my code: public override void VisitClassDeclaration(ClassDeclarationSyntax node) { var className = node.Identifier.Text; var namespaceName = (node.Parent as NamespaceDeclarationSyntax)?.Name.ToString(); var isAbastract = ?????? } 回答1: I've found the answer. here is the code: public override void VisitClassDeclaration(ClassDeclarationSyntax node) { var className

Get Attribute object from INamedTypeSymbol.GetAttributes() i.e. AttributeData object?

最后都变了- 提交于 2019-12-13 22:13:15
问题 I have defined the following attribute [AttributeUsage(AttributeTargets.Class)] class DemoAttribute : Attribute { public string SomeInfo { get; } public DemoAttribute(string someInfo) { this.SomeInfo = someInfo; } } which can be applied to some class as follows: [Demo("hello world")] class Program { } An INamedTypeSymbol variable namedTypeSymbol pointing to the Program class is provided to me with which I managed to get the name of the attribute. foreach(var attr in namedTypeSymbol

Unable to parse code snippet in roslyn

不打扰是莪最后的温柔 提交于 2019-12-13 19:53:57
问题 I'm trying to dynamically build a c# class from small pieces of code. We have a window where a user can enter c# code (valid or not), and we parse these strings into roslyn. I recently found an issue when i was using this : public override IEnumerable<StatementSyntax> GenerateStatements() { var result = new List<StatementSyntax>(); if (!string.IsNullOrWhiteSpace(this.Tag.Code)) { result.Add(SyntaxFactory.ParseStatement(this.Tag.Code)); } return result; } Turns out when compiling in VB, if the

How to create struct based properties with Roslyn

六月ゝ 毕业季﹏ 提交于 2019-12-13 16:16:51
问题 I have the following code to generate a property: Types: types = new Dictionary<string, SpecialType>(); types.Add("Guid", SpecialType.System_Object); types.Add("DateTime", SpecialType.System_DateTime); types.Add("String", SpecialType.System_String); types.Add("Int32", SpecialType.System_Int32); types.Add("Boolean", SpecialType.System_Boolean); generator.PropertyDeclaration(name, generator.TypeExpression(types["DateTime"]), Accessibility.Public); However, I always get an exception when the