This content is 7 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.
A few months ago, I was (along with about 70 other rMVPs) privileged to be on a Skype call with Scott Hanselman (@shanselman) as he gave an overview into Microsoft .NET Core. Some of what was discussed was confidential but the general overview of how .NET Core fits with the full .NET Framework and with Mono/Xamarin was a great education for a non-developer like me and it seems fine to reproduce it here for the benefit of others.
This is part 1 of a 2-part series, looking at .NET versions and the Microsoft .NET Core SDK. Tomorrow’s post moves on to look at Microsoft .NET Standard.
.NET versions
The first thing to understand is that .NET versioning is a mess [my words, not Scott’s]:
On a Windows machine with Visual Studio installed, open a command prompt and type clrver -all
. Chances are you’ll see versions 2.0 and 4.0. cd C:\Windows\Microsoft.NET\Framework
and on my Windows 10/Office 2016 machine I can see versions 1.0.3705, 1.1.4322, 2.0.50727 and 4.0.30319.
So where is .NET 3.0? Well, 3.0 and 3.5 were the Windows Presentation Framework (WPF) and Windows Communication Framework (WCF), running on v2.0 of the Common Language Runtime (CLR). They are actually part of Windows!
All of this makes developing for the .NET framework tricky. Side by side running for .NET 4.x is at the CLR level – if your app is developed for 4.6 and others are for 4.0, you may have a hard time convincing IT operations people to update and chances are you’ll need to drop down to 4.0.
That (together with cross-platform capabilities) is where .NET Core comes in.
Creating simple applications with the .NET Core SDK
.NET Core is in C:\Program Files\DotNet and is implemented as a driver (dotnet.dll). With a few simple commands we can create and run a console application:
dotnet new console
dotnet restore
dotnet run
That’s three steps to Hello World!
It’s just as simple for a web application:
dotnet new web
dotnet restore
dotnet run
Then browse to http://localhost:5000.
One difference in the web app is the presence of the
<Project Sdk="Microsoft.NET.Sdk.Web">
line in the .csproj file. This signifies a “meta package” – a package of packages that avoids explicitly listing multiple package references (for cleaner code).
Unlike in the (full) .NET Framework, we can specify the version of .NET Core to use in the .csproj file, meaning that multiple versions of the SDK can be used with whatever variety of libraries are needed:
<TargetFramework>netcoreapp1.1</TargetFramework>
We can also add references to libraries with dotnet add reference libraryname
. Adding a package with dotnet add package packagename
not only adds it but restores, downloads and checks compatibility. Meanwhile dotnet new solution
creates a solution file – something that would be complex to do manually.
Why revert to a CLI?
So we’ve seen that you can be a successful .NET programmer without a visual editor. We can build an entire project system from the command line. .NET Core is not just about involving the Linux community with a cross-platform version of .NET but also about speed and Scott used an analogy of thinking of the CLI as creating a “2D” version to validate before working on the full “3D” GUI version.
In the background (under the covers), the .NET Core SDK uses the NuGet package manager (dotnet add package
), MSBuild (dotnet build
) and VSTest (dotnet new xunit
and dotnet test
).
Visual Studio gives a better user interface but we can develop the basics very quickly using a command line and then get the best of both worlds – both CLI and GUI. What .NET Core does is lower the barrier to entry – getting up and running writing Microsoft.NET code in just a few minutes, for Windows, MacOS or Linux.
Resources