roslyn

How to use roslyn c# compiler with visual studio 2015?

核能气质少年 提交于 2019-11-26 19:09:53
问题 I've a bit of confusion about roslyn. What I have done: I've installed vs 2015 community edition and download in extensibilty > download compiler platform sdk. So I created a simple console application: hello world example. Well now I'm expect to choise the c# compiler between the vs2015 default one and roslyn..., but I've not found such option. So my first question is: how to select version of c# compiler? Second I've downloaded master-roslyn and I build, then I found csc.exe, well the odd

Delegate caching behavior changes in Roslyn

浪子不回头ぞ 提交于 2019-11-26 18:57:52
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>b__0); } Action<int> arg_1D_0 = C.CS$<>9__CachedAnonymousMethodDelegate1; } [CompilerGenerated]

Finding all references to a method with Roslyn

被刻印的时光 ゝ 提交于 2019-11-26 18:45:27
I'm looking to scan a group of .cs files to see which ones call the Value property of a Nullable<T> (finding all references). For example, this would match: class Program { static void Main() { int? nullable = 123; int value = nullable.Value; } } I found out about Roslyn and looked at some of the samples, but many of them are outdated and the API is huge. How would I go about doing this? I'm stuck after parsing the syntax tree. This is what I have so far: public static void Analyze(string sourceCode) { var tree = CSharpSyntaxTree.ParseText(sourceCode); tree./* ??? What goes here? */ } You're

Using C# 6 features with CodeDomProvider (Roslyn)

﹥>﹥吖頭↗ 提交于 2019-11-26 18:15:01
问题 CodeDomProvider objCodeCompiler = CodeDomProvider.CreateProvider( "CSharp" ); CompilerParameters objCompilerParameters = new CompilerParameters(); ... CompilerResults objCompileResults = objCodeCompiler.CompileAssemblyFromFile( objCompilerParameters, files.ToArray() ); When I compile my files I get: FileFunctions.cs(347): Error: Unexpected character '$' Does anyone know how to get string interpolation working with CodeDom compiling? I found this link: How to target .net 4.5 with

How to upgrade msbuild to C# 6?

霸气de小男生 提交于 2019-11-26 18:00:47
问题 I want to use C# 6 in my project (null propagation, other features). I've installed VS 2015 on my PC and it works brilliantly and builds test code like var user = new SingleUserModel(); //all model fields are null var test = user.User?.Avatar?["blah"]; But when I push my project to the repo and CI starts to build it, build fails because of unsupported ? . I've installed VS2015 on CI server too but looke like it doesn't use it. What can I do? CI - CruiseControl .NET Builds with C:\Windows

Publish website without roslyn

断了今生、忘了曾经 提交于 2019-11-26 15:13:54
问题 I am trying to create web application using Visual Studio 2015 and .NET 4.5.1. When I publish the website, visual studio create folder named roslyn . I know it's used to compile code on the fly, but unfortunately my hosting provider doesn't allow me to execute the compiler on their server. How to publish the website without roslyn like previous version of Visual Studio? EDIT: I got this error when trying to acces my website. It seems IIS trying to execute roslyn\csc.exe but my user account

C# 6.0 Features Not Working with Visual Studio 2015

心已入冬 提交于 2019-11-26 12:56:42
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? This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package CodeDOM Providers for .NET Compiler... Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn")

Can the C# interactive window interact with my code?

妖精的绣舞 提交于 2019-11-26 12:53:28
问题 I installed Roslyn. Now, if I know where to look in Visual Studio, I can open the \'C# interactive window\', and run code: > 5 + 3 8 That\'s cute. Now how can I interact my code —my classes? Assume I have a project open. > new Cog() (1,5): error CS0246: The type or namespace name \'Cog\' could not be found (are you missing a using directive or an assembly reference?) 回答1: When using Visual Studio 2015: You can open the Interactive window by navigating to Views > Other Windows > C# Interactive

Maybe a C# compiler bug in Visual Studio 2015

感情迁移 提交于 2019-11-26 12:28:09
问题 I think this is a compiler bug. The following console application compiles und executes flawlessly when compiled with VS 2015: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var x = MyStruct.Empty; } public struct MyStruct { public static readonly MyStruct Empty = new MyStruct(); } } } But now it\'s getting weird: This code compiles, but it throws a TypeLoadException when executed. namespace ConsoleApplication1 { class Program { static void Main(string[]

Microsoft Roslyn vs. CodeDom

…衆ロ難τιáo~ 提交于 2019-11-26 08:40:41
问题 From a press release yesterday on InfoWorld regarding the new Microsoft Roslyn: The most obvious advantage of this kind of \"deconstructed\" compiler is that it allows the entire compile-execute process to be invoked from within .Net applications. Hejlsberg demonstrated a C# program that passed a few code snippets to the C# compiler as strings; the compiler returned the resulting IL assembly code as an object, which was then passed to the Common Language Runtime (CLR) for execution. Voilà!