roslyn

TeamCity Build using C#6

ぃ、小莉子 提交于 2019-12-04 01:18:57
问题 We use TeamCity (9.0.1) as our build server, but having recently upgraded our ASP.NET MVC solution to use VS2015 and C#6 syntax, I now get the following error message on our build server: Can not start build runner and more specifically: C:\TeamCity\buildAgent\work\86ee61c6c333dc3d\MyApplication\MyApplication.csproj.metaproj : error MSB4025: The project file could not be loaded. Could not find file 'C:\TeamCity\buildAgent\work\86ee61c6c333dc3d\MyApplication\MyApplication.csproj.metaproj'. I

Get the SyntaxNode given the linenumber in a SyntaxTree

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:26:04
I want to get the SyntaxNode of a line given the location(lineNumber). The code below should be self-explanatory, but let me know of any questions. static void Main() { string codeSnippet = @"using System; class Program { static void Main(string[] args) { Console.WriteLine(""Hello, World!""); } }"; SyntaxTree tree = SyntaxTree.ParseCompilationUnit(codeSnippet); string[] lines = codeSnippet.Split('\n'); SyntaxNode node = GetNode(tree, 6); //How?? } static SyntaxNode GetNode(SyntaxTree tree,int lineNumber) { throw new NotImplementedException(); // *** What I did *** //Calculted length from using

Roslyn scripting: Line number information for run time exceptions

孤者浪人 提交于 2019-12-03 21:14:46
I am messing around with the Roslyn scripting stuff (using the Microsoft.CodeAnalysis.CSharp.Scripting nuget package), and I wonder if there is a way to add line number information to the stack traces for exceptions that happen inside a script. When I run the following C# code: // using Microsoft.CodeAnalysis.CSharp.Scripting; var code = @" var a = 0; var b = 1 / a; "; try { await CSharpScript.RunAsync(code); } catch (DivideByZeroException dbze) { Console.WriteLine(dbze.StackTrace); } The stack trace written to the console is: at Submission#0.<<Initialize>>d__0.MoveNext() --- End of stack

Show <returns> xml tag into visual studio intellisense

梦想的初衷 提交于 2019-12-03 20:35:54
问题 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? 回答1: 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

Understanding the various options for runtime code generation in C# (Roslyn, CodeDom, Linq Expressions, …?)

不羁岁月 提交于 2019-12-03 20:33:01
I'm working on an application where I'd like to dynamically generate code for a numerical calculation (for performance). Doing this calculation as a data driven operation is too slow. To describe my requirements, consider this class: class Simulation { Dictionary<string, double> nodes; double t, dt; private void ProcessOneSample() { t += dt; // Expensive operation that computes the state of nodes at the current t. } public void Process(int N, IDictionary<string, double[]> Input, IDictionary<string, double[]> Output) { for (int i = 0; i < N; ++i) { foreach (KeyValuePair<string, double[]> j in

Finding everywhere an enum is converted to string

蹲街弑〆低调 提交于 2019-12-03 16:37:07
问题 I'm currently trying to find everywhere in a solution where a specific enum is converted to a string, whether or not ToString() is explicitly called. (These are being replaced with a conversion using enum descriptions to improve obfuscation.) Example: I'd like to find code such as string str = "Value: " + SomeEnum.someValue; I've tried replacing the enum itself with a wrapper class containing implicit conversions to the enum type and overriding ToString() in the wrapper class, but when I try

.net Core amd Roslyn CSharpCompilation, The type 'Object' is defined in an assembly that is not referenced

喜欢而已 提交于 2019-12-03 11:04:35
I'm trying to port some .net code to the new Core runtime and I'm having a bad time porting some on-the-fly compilation. To resume, it always asks me for a reference to System.Runtime and mscorlib, but have no clue on how to reference them. As a side note, I can't reference Framework 4.6 as the project must be published to a Linux machine with .net Core. This is the minimum code: string testClass = @"using System; namespace test{ public class tes { public string unescape(string Text) { return Uri.UnescapeDataString(Text); } } }"; var compilation = CSharpCompilation.Create(Guid.NewGuid()

How to turn off Roslyn Code Fixes in VS 2015?

廉价感情. 提交于 2019-12-03 10:38:20
How can I turn off Roslyn Code Fixes in VS 2015? It works correctly (with the latest Resharper 9.1.2), but still while it initializes it blocks navigation, I mean Home, End, Left, Right are delayed for 0.5 - 1.5 seconds. Also it seems to be fool the nav keys, now it's the dozenth times I find myself in the VS main menu, or an other source file just by pressing the 4 nav keys I've listed, I don't know how... What I've tried so far: Look for in the Tools/Options and search for 'Roslyn' Context menu withing the Roslyn Code Fixes Google Native search in Stackoverflow Probably I am missing

Getting the fully qualified name of a type from a TypeInfo object

∥☆過路亽.° 提交于 2019-12-03 10:36:39
Is it somehow possible to get the fully qualified name of the type contained in a TypeInfo object? In the debugger many of these values nicely show up as System.Int32 but when it's printed out, not one of them contains this fully qualified name. I need this to provide as an argument to Type.GetType() . var typeInfo = semanticModel.GetTypeInfo(argument); var w = typeInfo.ToString(); // Microsoft.CodeAnalysis.TypeInfo var y = typeInfo.Type.ToString(); // int var z = typeInfo.Type.ToDisplayString(); // int var a = typeInfo.Type.OriginalDefinition.ToDisplayString(); // int var b = typeInfo.Type

Null propagation operator and dynamic variable

China☆狼群 提交于 2019-12-03 10:14:44
I have been looking at the null-propagation operator in C#6 and tried to make it work with the variables of dynamic type but without success. Consider the code below, it compiles but CLR throws AccessViolationException at runtime when the null-propagation is applied to dynamic object. class SomeType { public object SomeProperty { get; set; } static void Main() { var obj = new SomeType() { SomeProperty = "ABCD" }; var p1 = ((dynamic)obj).SomeProperty; //OK, p1 is set to "ABCD" var p2 = ((dynamic)obj)?.SomeProperty; //AccessViolationException Console.ReadLine(); } } At first I thought that this