Sunday, 18 October 2015

.Net 4.6

While starting to try to put me up to day with .Net 4.6 I've come up with a few interesting things. Let's see.

I already wrote some months ago about how .Net 4.5 is an in place replacement for .Net 4. With 4.6 is right the same, and the same technique described in that post applies in order to verify which is the .Net version that you have installed. If I check on my PC the version of the clr.dll, I'll see that it is now: 4.6.96.0.

As you know Microsoft has been working for a while on a new and improved JIT (Ryujit). In the past it was possible (I never tried it) to install it (protojit.dll) side by side with the standard one(clrjit.dll), and select one or another. In 4.6 this new JIT has become the standard, and as such has been renamed to clrjit.dll. The old JIT is distributed with the framework in the compatjit.dll file, and if needed you can force an application to revert to it by setting a value in app.config. It's explained here.

.Net 4.6 comes with C# 6, and the long awaited Roslyn. However, the whole thing is quite a bit bizarre. The csc.exe compiler that you'll find in the Framework installation folder (C:\Windows\Microsoft.NET\Framework64\v4.0.30319) is the old compiler, not based on Roslyn and with support only for C# 5. You can verify this by just trying to compile some code taking advantage of some new C# 6 feature. For example, trying to compile a program including a line like this:

int? length = list?.Count;

will give you these errors:

error CS1525: Invalid expression term '.'
error CS1003: Syntax error, ':' expected

So the new Roslyn based, C# 6 compiler is not installed with the Framework!!!

Microsoft has gone crazy or what?
The new compiler is installed when you install Visual Studio 2015, and seems to get placed in: $ProgramFilesx86$\MSBuild\14.0\bin (it's explained here). This appears not to be a big problem for most developers, as you can install Visual Studio Community for free, but as it's a fully functional Visual Studio, the installation is slow and painful. I really can not understand how you can install SharvDevelop in 1 minute and less that 50 MBs while installing Visual Studio continues to take hours and GBs and GBs.

Hopefully, for those few of us that don't plan to install VS 2015 (on my personal laptop), we can install Roslyn on its own in 1 minute anyway. You just need nuget (that by the way, can now also be installed and used on its own, just download the binary from the nuget site), and run this command:
nuget install Microsoft.Net.Compilers
as explained here.
The new C#, roslyn based compiler is still named csc.exe, but its version is:
Microsoft (R) Visual C# Compiler version 1.0.0.50618
while the version of the the non Roslyn compiler is:
Microsoft (R) Visual C# Compiler version 4.6.0081.0!!!

Yes, pretty bizarre, thanks Microsoft for adding more confusion to our lives... I have installed the Roslyn compiler to a Roslyn folder and renamed the binary to csc6.exe, cause as I have the folders for both the old and the new compiler in my path environment variable, I needed a way to make sure I'm using the correct one.

No comments:

Post a Comment