This is the first in a series of articles covering upcoming changes in Visual Studio 2015.

In the future I hope to explore the following areas which have undergone significant changes & enhancements:

  • IDE enhancements
  • .net 4.6 &.net Core 5
  • C#6
  • ASP.net vNext

Installing Visual Studio 2015

Before we get started its worth noting that if you want to play with the new features in Visual Studio 2015 yourself you have two choices:

  • Install the CTP 5 preview (Microsoft recommend that you may not want to do this on a production machine given this is a preview release).

  • Using an Azure machine image.

Roslyn

This release of Visual Studio contains a new version of C# & VB.net compilers code named “Roslyn”.

Roslyn is a complete rewrite of the C# and VB.net compilers with each written in their respective language for example the C# compiler is written in C# rather than C++. Roslyn is open source (Roslyn on GitHub) so you could even theoretically create your own version of C# or VB.net!

What would become Roslyn, was first mentioned way back in 2008 by Anders Hejlsberg at the PDC conference however it wasn’t until 2011 that the first preview was released.

Why develop a new version of the C# and VB.net compilers?

I suspect (despite what various articles & videos may emphasise) probably the main motivator for Roslyn was that the existing C++ based compilers were now over 10 years old & becoming difficult to maintain and expand – a complete redevelopment was needed. Roslyn however is a bit different to a "normal" compiler.

Traditionally compilers take one form of code that is human readable (e.g. C#) & transform it into another that is preferred by machines/run time environment (IL in C#’s case which is then run by the CLR).

This is a one way process: code goes in & code comes out.

Roslyn changes this and exposes each stage in the compilation pipeline to anyone that is interested.

Ok but why would you want to do this?

Exposing information from the pipeline has a number of benefits:

  • Improved refactoring/code analysis tools that really understand your code & the context it is operating in. Imagine for example security analysis tools that can crawl through your code at a deep level and finding potential security risks. Note that In Visual Studio 2015 Microsoft re-wrote many of the existing refactoring tools you are familiar with such as “Code Outling” & “Navigate to” to utilize Roslyn functionality!
  • Meta programming scenarios such as the creation of DSL’s (Domain Specific Languages) & embedding C#/VB.net within applications
  • Scripting APIs - REPL (Read Evaluate Print Loop) e.g. Roslyn's functionality allows you to run C# at design time into the IDE to test results

At the time of writing it looks uncertain whether the REPL and embedding C#/VB.net promises of Roslyn will make it to the Visual Studio 2015 release.

For example regarding REPL functionality the Roslyn team say:

_“The team is reviewing the designs of these components that you saw in previous CTPs, before re-introducing the components again. Currently the team is working on completing the language semantics of interactive/script code.” _

In addition to the compiler APIs that we have discussed Roslyn contains two other classes of APIs:

  • Diagnostic API’s for obtaining information about warnings & errors
  • Workspace APIs which represent the projects within a solution

Deeper into the Roslyn Compilation Process

The Roslyn compiler divides compilation into a number of stages:

  • Parsing –source code is divided it into tokens (items that have special meaning. The code is then transformed into an optimized grammar used in subsequent stages
  • Declaration –source code is used to create symbols
  • Bind – Identifiers are matched to symbols
  • Emit – the final stage in the process that produces an output

Hmm unless you are very familiar with compilers this probably sounds a bit abstract – let’s take a closer look at the parsing stage.

At the Parse stage Roslyn generates a syntax tree from the C# that you write. You can visualize the tree produced by installing the syntax visualizer extension or see Roslyn’s object representation online with Roslyn Quoter.

The below screenshot shows the syntax tree generated for a simple class with one variable:

Image alternative text

Yikes there is a lot going on there even for this simple code!

Yes it remains to be seen how much interest developers will have working at this low level and it is probably fair to say that by its very nature Roslyn is not the most straightforward of things.

Developers of add on tools certainly stand to benefit from Roslyn – however it is interesting to note that Jetbrains developer of Resharper (probably the most popular Visual Studio paid extension) say they will not be utilizing Roslyn.

In conclusion Roslyn exposes detailed information about the compiler pipeline & will enable the creation of the next generation code analysis & refactoring tools. Even through you may not work with Roslyn’s APIs directly you will no doubt benefit from improved tooling & new functionality that will be built upon the platform.

Further reading: