Archive december 2018

Visual Studio 2019, .NET Core 3.0, and C# 8.0

This week it has been really fun being a .NET developer. Previews of Visual Studio 2019 and .NET Core 3.0 has been made available to the community, making it possible to try out the new upcoming features.

I will not just repeat information that you can find on other sites, instead I will provide some good links, some tips on how to set up VS 2019 in order to test .NET Core 3 and C# 8, and some personal reflections.

Visual Studio 2019 Preview

You can find a summary on all the new features in Visual Studio 2019 in the official release notes and download it from the official site.

One feature that I find really interesting that I didn’t know about before testing the 2019 preview is Visual Studio Live Share which comes enabled by default in the preview. I had the opportunity to try it out with one of my colleagues running a test TDD session where he wrote the tests and I wrote the implementation. It was a lot of fun! Live share is also available for Visual Studio Code, so you are not limited to .NET development or even Windows.

I was also able to install extensions, such as VsVim, without any issues. So hopefully your favorite extensions in Visual Studio 2017 works in 2019 as well.

So far I haven’t had any major issues with the preview, I had one crash where it stopped responding and automatically restarted after a short while, but nothing else. I will however keep testing it and try out more complex use cases, such as profiling and visual editing of XAML files.

If you are interested in trying out new things I really recommend testing the preview. It can be installed alongside your current Visual Studio version without impacting it, so you will be able to continue to work as normal when you wish.

.NET Core 3.0 preview and C# 8.0

.NET Core 3.0 will support C# 8.0. The preview supports some of the new features such as Nullable References, Ranges and indicies, and Asynchronous Streams. You can read more about upcoming C# 8.0 features here.

Visual Studio 2019 Preview has support for .NET Core 3.0 but it requires some configuration. First you need to install Visual Studio 2019 and select to install the .NET Core workflow (it can be done later through the Visual Studio Installer if you forgot to add it initially). Then you need to download and install the .NET Core 3.0 Preview SDK, create a new .NET core project and configure it for .NET Core 3.0 and C# 8.0.

Also, Nullable References is not enabled by default so once you have configured your project to use .NET Core 3.0 and C# 8.0 you still have to edit your project file (.csproj) to enable it. Note that this has to be done for each new project you add to the solution.

A tip is to also configure your projects to ”Treat warnings as errors”. By doing that your code will not compile if you don’t handle possible null references properly.

New null-related errors

Conclusion

It feels like it will be a good year to be a .NET developer next year. The new Visual Studio 2019 has the potential to make a great IDE even better and .NET Core 3.0 and C# 8.0 will add new improvements that will make it easier to write cleaner and safer .NET code.



The different implementations of .NET

Even if you have been working with .NET for some time it can be hard to know the differences between the .NET Framework, .NET Core, and Mono. And what is this .NET Standard thing?

In this post I will describe the different architectural components of .NET and hopefully make all of this a bit clearer.

Implementations of .NET

Try to imagine that you are just starting out with .NET development. You open up Visual Studio for the first time ever to create a new C# project, and you are faced with this:

How on earth are you supposed to know what to choose? Even if you might figure out that it probably is easiest to start with a Console App, you still need to know whether you should choose the one ending with (.NET Core) or the one ending with (.NET Framework).

Let’s start by explaining the different implementations of .NET.

.NET Framework

This is the original .NET implementation that has existed since 2002 (announced 2000). It supports all the standard framework functionality, APIs, and a number of Windows-specific APIs. It is optimized for building Windows desktop applications, and is pretty much the only option if you are planning on building a graphical .NET application for the Windows desktop.

.NET Core

This is a newer implementation of .NET, version 1.0 was released in 2016. It is cross platform, i.e. it runs on Windows, macOS, and Linux. It supports the standard framework functionality but contains no support for building graphical user interfaces (this might change, for applications targeting Windows, in version 3.0, planned to be released sometime during 2019).

It is recommended to choose .NET Core for new desktop and server projects that does not require the Windows specific features that is part of the original .NET Framework.

Mono

The Mono implementation of the .NET framework is mainly targeting systems where a small runtime is needed, such as Android and iOS. But also games built with Unity and the new web framework Blazor, uses Mono. It supports the standard framework functionality as well as everything in .NET Framework 4.7 except Windows Presentation Foundation (WPF), Windows Workflow Foundation (WWF), limited Windows Communication Foundation (WCF) and limited ASP.NET async stack.

If you are targeting mobile, Unity, or Blazor, then you should read up on Mono.

Universal Windows Platform (UWP)

This implementation of .NET is intended for targeting touch-enabled Windows devices such as tablets and phones, and also the XBOX One. It supports the standard framework functionality as well as many services such as a centralized app store, an execution environment, and alternative Windows APIs.

Common APIs

While explaining the different implementations of .NET above I wrote that they ”support the standard framework functionality”. But what is that?

.NET Standard

There is some confusion around .NET Standard and how it fits into the .NET ecosystem. Let’s clear it out. .NET Standard is a set of APIs that is common to all implementations of .NET.

In other words, .NET Framework implements .NET Standard, and so does .NET Core and Mono. This means that if you create a library that targets .NET Standard, it will be compatible with all implementations of .NET.

I will not be able to list the APIs in .NET Standard. The current version, 2.0, includes more than 32 000 APIs. You can however find the complete listing here.

Components of a .NET implementation

Now that we know how different implementations of .NET have different use cases, and that they implement a set of standard APIs, we can take a look at what makes up an implementation of .NET. As part of the implementation you can expect to find:

  • One or more runtimes, such as the Common Language Runtime (CLR) for the .NET Framework, and CoreCLR for .NET Core
  • A library that implements the .NET Standard APIs, such as the Base Class Library (BCL) for the .NET Framework and .NET Core

There are also some optional components such as:

  • WPF and WCF for the .NET Framework
  • Different compilers
  • Tools for organizing your code into projects and projects into solutions
  • Tools for handling and organizing external libraries, for example nuget

Conclusion

As we have seen there are several different implementations of .NET. However, they all have slightly different use cases, even though there is some overlapping. When you have finished reading through this post you hopefully have a good enough understanding on the differences to know which implementation that is suitable for your use case.