roslyn

Avoid significant amounts of packages and binaries when using Roslyn with Nuget

僤鯓⒐⒋嵵緔 提交于 2019-12-24 10:36:50
问题 I'm trying to make use of Roslyn in my application. I added the NuGet package for that ( Microsoft.CodeAnalysis.CSharp ). It turns out that this package depends on many others: Most of them seem unused on the .NET Framework (e.g. System.Runtime which provides types such as Int32 ). There is an incredible contrast between the size of those packages and what is actually being used. A lot of the data appear to be translations: (I'm not saying someone did a bad job here. I'm not competent enough

Make MSBuild use new Roslyn compiler in VS15 Preview

梦想与她 提交于 2019-12-24 08:25:00
问题 I just recently delved into Roslyn compiler stuff and I'm wondering about some possibilities. I'm trying to build Roslyn compiler from Roslyn repository using features/tuples branch and replace the needed DLLs in VS15Preview\MSBuild\15.0\Bin folder. But when I replace DLLs and build console app project I receive the following error message Severity Code Description Project File Line Suppression State Error The specified task executable "csc.exe" could not be run. Could not load file or

Roslyn VSIX Extension Blows up from adding function in fix provider

眉间皱痕 提交于 2019-12-24 07:01:09
问题 I've been dealing with an issue I'm going to assume is environment specific. I installed and reinstalled the Roslyn Templates when I add any function to the CodeFixProvider(Referenced or not). VS blows up with an system aggregate exception when trying to open the preview window: This is the full code fix provider the only thing modified is adding the new function [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AggregateBugAnalyzerCodeFixProvider)), Shared] public class

How to get workspace from VisualStudioWorkspace?

我怕爱的太早我们不能终老 提交于 2019-12-24 06:35:09
问题 I'm trying to get Workspace from visual studio to use it with roslyn. I found some topics about that, like this one : How to get reference to 'Roslyn' Workspace object from IVsSolution? I wrote exactly the same code : var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)); var workspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>(); But I get this error... "No exports were found that

Does Roslyn actually allow you to manipulate TreatWarningsAsErrors for a CSharp project?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 02:54:08
问题 I'm trying to retrieve the setting TreatWarningsAsErrors, but I'm unable to find it for a project of my loaded solution. What I'm trying to accomplish, is to get the setting from the project files, and set it to true , if it's not already that. Next, I want to let Roslyn do a compilation with the new setting, so I can check if this will break the project. I've looked at various places, among others, the Project.CompilationOptions . Most options to a project build are there, except this one.

VS 2015, C# 6, MVC5, Roslyn — 502 gateway errors on Azure web app

时光毁灭记忆、已成空白 提交于 2019-12-23 23:29:15
问题 I'm in the process of diagnosing this issue and I will update as I learn more but I wanted to post what I have in case there's a quick fix/someone's seen this already. I have a MVC5 project, .NET 4.5.2, Visual Studio 2015. I recently started using C# 6 so in order to get Razor to work I had to install the CodeDOM compiler Nuget package. Everything works on my local machine (of course it does). My current stable Azure site is on a Git commit that is NOT using C# 6, but is using .NET 4.5.2 and

Calling Roslyn Analyzers from command line

*爱你&永不变心* 提交于 2019-12-23 21:26:49
问题 Using Roslyn Analyzers while developing in Visual Studio 2015 is great. However, it would be even greater to be able to call analyzers from a pre-commit hook or a CI like TeamCity in order to make sure non-conformant code is flagged. Is there any way to get the results of an analyzer by calling a command line utility or will this need to be custom made? 回答1: Roslyn Analyzers can be ran by csc.exe or vbc.exe (the compilers themselves), so just invoke the compiler. Assuming your Continuous

Resolving parameter type in Roslyn

早过忘川 提交于 2019-12-23 20:29:52
问题 I'm using Roslyn to implement custom business rules. At the moment, I'm a bit stuck, I have to validate the type of a parameter when a method is being invoked. There are no issues validating that the method is being invoked or that is contains parameters. I have resolve an IdentifierNameSyntax by using GetSymbolInfo to get the symbol of my current syntax. It's not null and has the information I'm looking for such as the following : CandidateReason: None CandidateSymbols: Length = 0 Symbol:

How to get module ancestor in roslyn semanticmodel?

拟墨画扇 提交于 2019-12-23 18:13:59
问题 I'm looking to get ancestor from a module's roslyn semanticmodel. In a class like this : namespace Name1.Name2 { using System; ... public partial class MyClass : Ancestor<Param1, Param2> { } } So I'm trying to get Ancestor<Param1, Param2> (and later Param1 and Param2 ). I'm using this code to create the semanticmodel : SyntaxTree tree = CSharpSyntaxTree.ParseFile(moduleAutoGenPath); CompilationUnitSyntax root = (CompilationUnitSyntax)tree.GetRoot(); var nameSpace = (

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