So now we all know what Roslyn is, let's take a look at how we can use it to compile a project in memory.
What's more, you can also harness Roslyn for other purposes such as tests that fail as soon as common code smells are introduced into a project. This opening up of the C# compiler has resulted in a whole array of code analysis tooling such as better StyleCop integration and debugging tools like OzCode and the like. For the past couple of years Microsoft have been rewriting the C# compiler in C# (I know, it's like a compiler Inception right?) and opening it up via a whole host of APIs that are easy to prod, poke and interrogate. This has since changed with the introduction of Roslyn. NET platform provided no assistance with this, essentially meaning they had to duplicate a lot of the work the compiler was doing.
In order for the ReSharper team to provide this they had to build their own analysis tools that would manually parse your solution's C# inline with the. Take ReSharper for instance Resharper has a lot of code analysis running under the bonnet that allows it to offer refactoring advice. Traditionally compilers have been a black box of secrets that are hard to extend or harness, especially for any tooling or code analysis purposes. The key words to take away with you here are "compiler as a service" let me explain. Roslyn is an open-source C# and VB compiler as a service platform.
dll from disk then extract the IL, or do I compile the project in memory behind the scenes, then stream the assembly to Roslyn? Ultimately I went with the later approach and was pleasantly surprised at how easy Roslyn makes this - surprised enough that I thought it deserved its own blog post.īefore we continue, let me take a moment to explain what Roslyn is for those that may not fully understand what it is. This introduces a question though, do I build the solution (blocking the user whilst their project is building), read the. Recently I've been hard at work on my first Visual Studio Code extension and one of the requirements is to extract IL from a.