Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
I always wondered how you could specify the C# version in your project. One of the cool new features in C# 7.1 that I’ve been looking forward to is the “Async Main“. But to be honest, I had no idea how, even when C# 7.1 is released, how I would be able to start use it and its new features. A few days ago I stumbled upon this an issue in the Microsoft Docs repo.The C# build system now includes a node inside a csproj file that controls which version of C# the compiler should follow.
Visual Studio
With the Visual Studio 2017.3 update being just released, I figured I’d try to figure out how to enable C# 7.1. It’s kind of buried a bit but you can also edit your csproj by hand fairly easily, which will come next. If you’re in Visual Studio, in your project properties under the Build Tab, click the “Advanced…” button.Manual Editing
The good news is with the new csproj files, you can make this edit manually. So if you are outside of Visual Studio, it’s as simple as defining a<LangVersion>
.
Target Versions
Per the issue above, as well as you can see if you are in Visual Studio, the possible versions you can target are:- ISO-1
- ISO-2
- C# 3.0
- C# 4.0
- C# 5.0
- C# 6.0
- C# 7.0
- C# 7.1 (beginning with .NET Core 2.0)
- latest (latest minor version)
- default (latest major version)
I guess you mean Visual Studio *2017*, rather than 2018 😉
Ooops! Thanks. Updated
Right now C# 7.1 is in early preview.
<LangVersion>
and the properties page edit for it have been around for a long long time =) I believe if you try to do async main, you’ll get a Roslyn code fix on it which automatically sets the langversion for you. That’s true at least for some C# 7.1 features.