Sponsorship is available! If you’d like to sponsor CodeOpinion.com and have your product or service advertised exclusively (no AdSense) on every post, contact me.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 StudioWith 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 EditingThe 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
Target VersionsPer the issue above, as well as you can see if you are in Visual Studio, the possible versions you can target are:
- 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)