Questions tagged [roslyn]

Roslyn (aka .NET Compiler Platform) provides open-source C# and Visual Basic compilers with rich code analysis APIs. It enables building code analysis tools with the same APIs that are used by Visual Studio.

Written in 100% managed code, the Roslyn project exposes the C# and VB compilers as a service.

Historically, the managed compilers we’ve shipped in Visual Studio have been opaque boxes: you provide source files, and they churn those files into output assemblies. Developers haven’t been privy to the intermediate knowledge that the compiler itself generates as part of the compilation process, and yet such rich data is incredibly valuable for building the kinds of higher-level services and tools we’ve come to expect in modern day development environments like Visual Studio.

With these compiler rewrites, the Roslyn compilers become services exposed for general consumption, with all of that internal compiler-discovered knowledge made available for developers and their tools to harness. The stages of the compiler for parsing, for doing semantic analysis, for binding, and for IL emitting are all exposed to developers via rich managed APIs.

Useful resources

Tips & Tricks

2826 questions
1264
votes
60 answers

Could not find a part of the path ... bin\roslyn\csc.exe

I am trying to run an ASP.NET MVC (model-view-controller) project retrieved from TFS (Team Foundation Server) source control. I have added all assembly references and I am able to build and compile successfully without any error or warning. But I…
Eyad
  • 13,440
  • 6
  • 26
  • 43
205
votes
5 answers

Can the C# interactive window interact with my code?

In Visual Studio 2015 or later, 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'…
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
164
votes
4 answers

In which language is the C# compiler written?

I looked at the source code at http://referencesource.microsoft.com/, and it appears all the source code is in C#. I also looked at the source code for the new C# compiler platform (Roslyn), and it is also in C#. How is that possible? Is C# language…
CriketerOnSO
  • 2,600
  • 2
  • 15
  • 24
139
votes
7 answers

C# 6.0 Features Not Working with Visual Studio 2015

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…
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
136
votes
5 answers

VS2015 build fails with no error message with Dynamic

I was writing a unit test on a piece of code that returned JSON. The type that it returns is an anonymous type, so I thought to verify the values on it I'd just cast the object to a dynamic to do my assertions. However, when I do that, my build…
DLeh
  • 23,806
  • 16
  • 84
  • 128
132
votes
2 answers

Is nameof() evaluated at compile-time?

In C# 6, you can use the nameof() operator to get a string containing the name of a variable or a type. Is this evaluated at compile-time, or at runtime via some Roslyn API?
Gigi
  • 28,163
  • 29
  • 106
  • 188
127
votes
1 answer

Are Roslyn SyntaxNodes reused?

I've been taking a look to Roslyn CTP and, while it solves a similar problem to the Expression tree API, both are immutable but Roslyn does so in a quite different way: Expression nodes have no reference to the parent node, are modified using a…
Olmo
  • 4,257
  • 3
  • 31
  • 35
120
votes
5 answers

Microsoft Roslyn vs. CodeDom

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…
mellamokb
  • 56,094
  • 12
  • 110
  • 136
108
votes
3 answers

How to upgrade msbuild to C# 6?

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 =…
Anna Prosvetova
  • 1,427
  • 2
  • 10
  • 14
98
votes
5 answers

Using System.Dynamic in Roslyn

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…
Rush Frisby
  • 11,388
  • 19
  • 63
  • 83
95
votes
4 answers

Roslyn failed to compile code

After I have migrated my project from VS2013 to VS2015 the project no longer builds. A compilation error occurs in the following LINQ statement: static void Main(string[] args) { decimal a, b; IEnumerable array = new string[] {…
ramil89
  • 851
  • 13
  • 22
94
votes
6 answers

Publish website without roslyn

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…
Niyoko
  • 7,512
  • 4
  • 32
  • 59
92
votes
2 answers

Why are async state machines classes (and not structs) in Roslyn?

Let’s consider this very simple async method: static async Task myMethodAsync() { await Task.Delay(500); } When I compile this with VS2013 (pre Roslyn compiler) the generated state-machine is a struct. private struct d__0 :…
gregkalapos
  • 3,529
  • 2
  • 19
  • 35
88
votes
5 answers

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

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…
EdSF
  • 11,753
  • 6
  • 42
  • 83
74
votes
1 answer

Where has the Code Analysis window gone?

In Visual Studio 2013, I used the Code Analysis window to provide reports to both the Development and Management teams. In Visual Studio 2015 Enterprise RTM, these errors have returned to the error window and I can no longer just see CA issues for…
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
1
2 3
99 100