roslyn

Using System.Dynamic in Roslyn

风流意气都作罢 提交于 2019-11-27 11:50:16
问题 I modified the example that comes with the new version of Roslyn that was released yesterday to use dynamic and ExpandoObject but I am getting a compiler error which I am not sure how to fix. The error is: (7,21): error CS0656: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create' Can you not use dynamics in the new compiler yet? How can I fix this? Here is the example that I updated: [TestMethod] public void EndToEndCompileAndRun() { var text = @"using

How to upgrade msbuild to C# 6?

风格不统一 提交于 2019-11-27 11:24:10
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\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe jessehouwing Make sure you call: C:\Program Files (x86)

Can the C# interactive window interact with my code?

断了今生、忘了曾经 提交于 2019-11-27 10:45:57
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?) When using Visual Studio 2015: You can open the Interactive window by navigating to Views > Other Windows > C# Interactive , Then just right click your project and run Initialize Interactive with Project from the context menu. For

Publish website without roslyn

坚强是说给别人听的谎言 提交于 2019-11-27 10:28:56
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 doesn't have permission to do that. With previous version of Visual Studio, this error doesn't show up. I

Building a SyntaxTree from the ground up

半腔热情 提交于 2019-11-27 10:20:43
问题 I previously asked this question, which was answered, but someone gave a suggestion that might help me prevent making similar mistakes as I move forward. Adding Auto-Implemented Property to class using Roslyn The suggestion was that I build the Syntax Tree from the bottom up and not from the top down. Could someone provide a small demo or a link that shows how I would do this from the ground up? Here is the code again: var root = (CompilationUnitSyntax)document.GetSyntaxRoot(); // Add the

C# 6.0 TFS Builds

扶醉桌前 提交于 2019-11-27 08:53:19
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? For the compilation step, you have a couple of options: You can reference the Microsoft.Net.Compilers NuGet package on a per-project basis to use that

Difference in CSC and Roslyn compiler's static lambda expression evaluation?

↘锁芯ラ 提交于 2019-11-27 07:47:06
问题 Consider the following example code. class Program { static void Main( string[] args ) { DoSomethingWithAction( i => { Console.WriteLine( "Value: {0}", i ); } ); Console.ReadLine(); } private static void DoSomethingWithAction( Action<int> something ) { Console.WriteLine( something.Target == null ? "Method is static." : "Method is not static." ); something( 5 ); } } If I compile and run this code under Debug using the Visual Studio 2010 (under CSC compiler) it will print out the following

Roslyn Get Method Declaration from InvocationExpression

匆匆过客 提交于 2019-11-27 07:18:36
问题 I'm making a roslyn demo for generating compiler warnings from attributes I have an analyzer to analyze Method Invocations which looks like so: public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeAction(AnalyzerInvocation, SyntaxKind.InvocationExpression); } private static void AnalyzerInvocation(SyntaxNodeAnalysisContext context) { var invocation = (InvocationExpressionSyntax)context.Node; } I'm trying to figure out how to get the method declaration, I know I

Get fully-qualified metadata name in Roslyn

隐身守侯 提交于 2019-11-27 05:49:24
问题 I need to get the full CLR name of a particular symbol. This means that for generic types I need the `1 , `2 , etc. appended to types. Now, ISymbol already has a property MetadataName which does exactly that. But it excludes surrounding types and namespaces, only giving the name of the symbol at hand. The usual option for getting a fully-qualified name, i.e. via ToDisplayString doesn't quite work here because it will not use the MetadataName for its various parts. Is there anything like this

Can Roslyn generate source code from an object instance?

那年仲夏 提交于 2019-11-27 02:58:15
问题 Using the Roslyn API with Visual Studio 2015, can I convert an object instance to source code? Can I create an extension method like ".ToSourceCode()" as shown below? class Foo { } class Program { static string classSourceCode = "class Foo { }"; static void Main() { var instance = new Foo(); var instanceSourceCode = instance.GetType().ToSourceCode(); System.Diagnostics.Debug.Assert(instanceSourceCode == classSourceCode); } } 回答1: No. However, ILSpy can. Based on the comments on the question