Visual Studio Code: Roslyn and OmniSharp with the C# compiler on Windows

(A month is a long time in .Net, right now. Looking back at this, it clearly predates my getting to grips with project.json. I’m leaving it here as I find it instructive to leave my naive attempts in place.)

  • Visual Studio 2015: I abbreviate this to VS
  • Visual Studio Code: I abbreviate this to VSC


This is aimed at C# programmers on Windows, who are used to doing all their editing and dev compilation in VS. In VSC, you can edit existing .cs files which are already part of a parent .sln file. Doing this, you will get Intellisense and a whole bunch of richness. However if you create new .cs files, then to get Intellisense etc, you must first go to VS and add that new file to a .csproj and .sln (or write some command line transformer to add the .cs files… or a Task in VS). With a little one-off effort, you can compile inside VSC. 

If you are using VSC on Windows, and you are writing C#, and you want OmniSharp and Intellisense to work… then you must have a VS Solution in place. I emphasise that, because I first did not entirely digest this point here:


As a C# programmer, just heed the stuff in the orange borders. As ever, some screenshots illustrate the point. Firstly, this is what happens if you naively open a .cs file in VSC that does not ultimately have a parent .sln file:


After typing [System.] above, I pressed [ctrl-space], which returns [No suggestion]. That is because App1.cs is standalone, and has no VS Solution context. It is however perfectly valid C#  (once I fix the syntax):


But if in VS I now create a simple console app, and therefore get a .sln file, with the simple .cs existing in the context of that Solution, we see this in VS:


I then locate the solution in VSC:


, and open the program file. We then get all the Intellisense and OmniSharp checks:


Doing a bit more editing shows that you get:

  • IntelliSense (as said)
  • Redundant Usings warnings
  • A summary of warnings
  • snippet/auto completion (I haven’t yet worked out where it gets these), but e.g. CW does the right thing
  • Code formatting (I haven’t worked out how you set this to your standards)
  • Code Lens


So all in all, I THINK it was worth the pain… my use-case is that for the trade-off of creating at least a skeleton project in VS, I can edit on a non-full-power box. But right now, I see this being more for a scratchpad or POC application, rather than an enterprise-size application. That might not be true for an AngularJS app – I suspect it is not true given all the passion on Twitter etc for this from JavaScript people. But it does have a very small footprint. I have a Linx 2GB/32GB Windows 10 tablet, and whereas it struggled to cope with a full VS environment, I’m sure this will be easy for it. That is the use-case I guess (note I am specifically talking about C# usage, not JavaScript etc)

And note that you don’t somehow download OmniSharp, or direct VSC to find it as an extension. No, it is evidently part of VSC, on Windows anyway.

Roslyn: First Steps

Roslyn, AKA the .Net Compiler Platform, is used in Visual Studio 2015 for the C# and Visual Basic compilers. MS Blog. My motivation is that I want a simple, small C# compiler footprint that I can use with Visual Studio Code.

Now Visual Studio is anything but lightweight (they REALLY got this naming wrong between VS and VS Code)… but if you go to Roslyn on GitHub, download Nuget.exe as Raw, go to Powershell I guess as Administrator, and run this:

.\nuget.exe install Microsoft.Net.Compilers

then you get the csc.exe and its dependencies.

Screenshots to cover all that:












OmniSharp02 OmniSharp03



OmniSharp06 OmniSharp07

Compilation using csc.exe

We then come to actually compiling something trivial. msdn guidance here.

This is a linked page from there to the simplest possible console app. Just SO disappointing in a page about VS2015, they’re using a Windows Batch script to wrap it and not PowerShell. Anyhoo… if you have this content:

(tidy up another time)

Link to the Roslyn wiki on GitHub: