Introduction

The Roslyn team started by re-implementing the compiler in C#. That means that developers can clone the company's compiler for C# projects and add their own features, as well as suggest new features for Microsoft to implement in the compiler itself. Roslyn is open source! The .Net Compiler Platform, also known as "Roslyn", is the most awaited project of Microsoft. The C# and VB teams got together and rewrote the compilers and language services in managed code, replacing a horrible mess of C++ code (with some managed code) that had mutated over the past ten years into a complex and difficult-to-modify code base.

The Roslyn compiler fetches information regarding the entire source code like what and which type of elements are present in the code, what the real meanings of those elements are, how they are communicated and related to the each other and the IL emitting (executable code). The Visual Studio templates available for both Visual Basic and C# installed with the Community Technology Preview are Console Applications, Code Issues, Code Refactoring and Completion Provider.

Roslyn allows us to easily write C# (or VB) code that parses a source file and rewrites the code. This makes it easy to build many tools to analyze or modify source code. Roslyn exposes a simple extensibility model that lets you create your own warnings or refactorings that integrate with Visual Studio. Thanks to the newly accessible semantic information, Roslyn includes a number of new Refactoring and has vastly improved the existing ones (especially Rename).

work flow of Roslyn compiler

Installation Procedure for Roslyn compiler

To properly install the Roslyn compiler in ASP.NET we need to do the following two things:

The Roslyn API(s) are available as NuGet Packages, so you can install it very easily using the Package Manager.

PM> Install-Package Roslyn.Compilers.Common

Once the installation is successful, create a sample console application or a Web Application as needed and add the reference to the two libraries, that you got from the preceding installation. The two libraries are:

Why the Roslyn compiler is in ASP.NET

Enabling the new Roslyn compilers in your ASP.NET application will result in the following two main benefits:

Roslyn Layers

Roslyn mainly has the following four API layers:

Roslyn API

Security performances

The Roslyn compiler can only execute only that programming code that the code (application) could already execute and push it on the Visual Studio .NET Framework with the similar security aspects and issues. In that way, it does not do any new security aspects that are not already present. But the main advantage of Roslyn is that it makes the code easier than code that was written before. Dynamically executing code at run time has always been problematic. The potential exists for an application to execute malicious code in a way that may not be easily detected by current virus scanners.

How to use the Roslyn compiler

Design principals

Data structures created by Roslyn compilers are present in the immutable format and can't be changed during calling application. This is forcefully necessary to keep from crashing the compiler. Also, the initial problems introduced by allowing changes in the compile process are not allowed. The syntax tree provided to the Roslyn user is a read-only snapshot of the compiler's current understanding of the code. Rebuilding a full syntax tree at each code change would be not allowed from a performance and memory consumption view. The main challenge for Roslyn was how to immediately surface an immutable data collection from a core syntax tree that was modified live as well as code changed by the developer.

How Roslyn influences the future development of the C# compilers

For influencing the compiler in the future we use the Delphi IDE. The Delphi IDE is a very important IDE. The Delphi IDE was programmer-friendly and has a user friendly environment that included many nice touches, it was very popular because the developers wanted those features in their code. We know that any software in the C# and VB compilers are not fully bug-free. The Roslyn team worked with the dilemma to find errors in the new code or fix them. Sometime, the decision was good to fix the bug even if it can create the problem in the code but sometimes it played a very important role for the future prospective to make the software more reliable. By verifying our solution with Roslyn we can avoid errors in the future and are able to fix it without hurrying.

Summary

The Roslyn compiler exposes a set of Compiler APIs and Services APIs that provide rich information about our source code. It provides many functionalities, like IntelliSence, reformatting and many more through which our code becomes more reliable and useful for the user. It also provides language interoperability and multiple language support. The .NET Compiler Platform (“Roslyn”) exposes a set of Compiler APIs and workspace APIs that provide rich information about your source code and that has full fidelity with the C# and Visual Basic languages. The transition to compilers as a platform dramatically lowers the barrier to entry for creating code-focused tools and applications. It creates many opportunities for innovation in areas such as meta-programming, code generation and transformation, interactive use of the C# and VB languages and the embedding of C# and VB in domain specific languages.