Roslyn Compilers – Vnext Feature

In our features about vnext, we saw about No compiler developer experience and compiler as a service. The black box magic of compilers is revealed in Vnext. It is called Roslyn compilers.

  • Roslyn compilers are next generation of compilers that will come up in vnext.
  • Going forward, our dependency on IDE for intelligence, Go to definition and various code analysis tools for code refactoring, code generation to improve our quality increases linearly. As these tools get smarter, they need access to more and more of the deep code knowledge that only compilers possess.

This is the core mission of the .NET Compiler Platform (“Roslyn”): opening up the black boxes and allowing tools and end users to share in the wealth of information compilers have about our code. Instead of being opaque source-code-in and object-code-out translators, through the .NET Compiler Platform (“Roslyn”), compilers become platforms—APIs that you can use for code related tasks in your tools and applications.

This directly relates using the compiler as a service on cloud. You change the C# code by refreshing the browser. When there is an emphasis on moving towards accepting everything as a service, being an open source gives us a lot of flexibility to develop our code analysis tools, rules that we would like to impose for a better code quality. At the same time if it’s on the cloud, it can be used across projects. You never know you can be a Cloud Service provider for compilers 🙂

Here I would like to take you through about the compilers API which is out as an alpha version. This is also handy with VS 2013 package.

The .NET Compiler Platform (“Roslyn”) exposes the C# and Visual Basic compiler’s code analysis to you as a consumer by providing an API layer that mirrors a traditional compiler pipeline. The .NET Compiler Platform (“Roslyn”) consists of two main layers of APIs – the Compiler APIs and Workspaces APIs.

Compiler APIs

  • It has an object model that corresponds to a traditional compiler pipeline, one is syntax based, the other one is semantic based
  • Contains an immutable snapshot of a single invocation of a compiler, including assembly references, compiler options, and source code files
  • 2 distinct APIs that represent the C# language and the Visual Basic language.
  • No dependencies on Visual Studio components

WorkSpace APIs

  • The Workspaces layer is the starting point for doing code analysis and refactoring over entire solutions
  • In this layer, all the information about your project is organised into a single object model
  • Now you form the same structure as a traditional compiler pipeline and you get access to compiler object model like source text, syntax trees, semantic models and compilations without needing to parse files, configure options or manage inter-project dependencies
  • Offers you direct access to Host environments, like an IDE, provide a workspace for you corresponding to the open solution. It is also possible to use this model outside of an IDE by simply loading a solution file

In my next blog about vnext, I will take you through the features that can surprise most of us. Yes, Microsoft gave a nod to Hadoop. Who doesn’t want to enter Big Data. The Map Reduce for C# is the next announcement. Kindly share your views on this. It will definitely help us to build our own API.


Tags: ASP .Net vNEXT, Roslyn Compiler, Software Development
previous post: Roslyn – Compiler Magic next post: Whats new in Microsoft Dynamics SL 2015