Saturday 9 June 2012

Using Roslyn to Load and (quickly) Compile C# Solution files (outside VisualStudio)

Now that we can use Roslyn to compile (and create assemblies) in real-time the next step is to use it to open up and consume C# Solution files (something that I've always wanted to do properly without needing to use VisualStudio or deal with the xml format used by the *.sln files).

To try and learn Roslyn Solution/Project capabilities, I created an O2 Platform tool (which is an C# Script developed using O2's REPL Script environment) which allows the easy load and compile of Solution files (using Roslyn compiler not the CSC compiler). Here is Video of this tool in action:

Some comments:
  • I was able to easily open up C# Solutions/Projects and have access to the project's C# files using pretty powerful/easy-to-use Roslyn APIs
  • The compilation of solutions/projects is also quite fast (using Roslyn not the CSC.exe compiler)
  • There are a number of C# coding capabilities that are not implemented in Roslyn, for example 'object creation expression with initializer' (which causes most errors seen in the video)
  • Note how I was able to quickly fix one of those errors and recompile the code :)
  • The SuperSecureBank.sln compiled OK, so next step is to see if can get the same environment and speed shown in the Real-Time compilation and security scan (using Cat.Net) PoC.

Here is a document that shows the evolution of this script:

Related Posts: