Using C# 8 on Visual Studio 2019 for Mac Preview

With Visual Studio 2019 Preview you can start to play with C# 8 and its great new features. While on Windows you only needs to install Visual Studio 2019 and .NET Core 3.0, on Mac you needs some additionally trick to make it works. In this post we’ll see how you can use C# 8 Preview with Visual Studio 2019 for Mac Preview.

Prepare your Mac

First of all, you need to download and install the following packages:

After installation is complete, start Visual Studio 2019 for Mac Preview and create a .NET Core Console Application:

Create Console Application

Setting up your project

Now, click on projects Options > General and then set Target Framework to .NET Core 3.0:

Set Target Framework

To successfully build the project, you need to add the Microsoft.Net.Compilers package, preview version, from NuGet:

Add Microsoft.Net.Compilers package

Finally, edit the .csproj and add the following xml elements:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <LangVersion>Preview</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <LangVersion>Preview</LangVersion>
</PropertyGroup>

You can check the full list of LangVersion here.

Start to play with C# 8

Ready to write you first C# 8 app? Go!

Your first C# 8

Check here what’s new in C# 8 and give it a try!

Note Most of the C# 8.0 language features will run on any version of .NET, but a few of them, like Async streams, indexers and ranges, all rely on new framework types that will be part of .NET Standard 2.1

UPDATE Visual Studio 2019 for Mac Preview 3

With the recently released Preview 3, you can set the C# language to Preview directly on project options:

Visual Studio 2019 Preview 3

Update it if you have already installed!

Found a problem? Edit this post