My VSCode debugger says that I'm using c# 4. I can't find any docs about getting VSCode to switch to C# 7. I'm on Windows 10. I don't know if this is a DotNet Core issue, a VSCode issue, or an Omnisharp issue. I would appreciate someone pointing me to a set of instructions or posts that solved this problem.
A snipet from the top of my VSCode .csproj file:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <LangVersion>4</LangVersion> </PropertyGroup>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
These are my VSCode versions:
Version: 1.27.2 (user setup)
Commit: f46c4c469d6e6d8c46f268d1553c5dc4b475840f
Date: 2018-09-12T16:17:45.060Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3 V8: 6.1.534.41
Architecture: x64
.NET Core SDK version 2.1.402 (x64)
You have to change it so it runs in the terminal. Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration.
Install Visual Studio Code. Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries.
As you've pointed out in the portion of your question where you posted the csproj, the current language version is set to 4.
<LangVersion>4</LangVersion>
You can get the latest features for C# 7.3 by setting it to <LangVersion>7.3</LangVersion>
If you merely want the C# 7.0 features, you can set the value to <LangVersion>7</LangVersion>
This document lists the (currently) valid options that can be passed to the -langversion
compiler flag. If you want your project to always compile with the latest available version of C#, you can set the value to <LangVersion>latest</LangVersion>
in your .csproj
. Of course, this will only compile to the latest version supported by your version of the compiler.
The behavior of the default value has changed in recent versions of the compiler. The document accurate at the time of editing is this one, which states the following:
The compiler determines a default based on these rules:
Target framework | Version | C# language version default |
---|---|---|
.NET Core | 6.x | C# 10.0 |
.NET Core | 5.x | C# 9.0 |
.NET Core | 3.x | C# 8.0 |
.NET Core | 2.x | C# 7.3 |
.NET Standard | 2.1 | C# 8 |
.NET Standard | 1.x/2.0 | C# 7.3 |
.NET Framework | all | C# 7.3 |
You just need to update your
<PropertyGroup> <LangVersion>4</LangVersion> </PropertyGroup>
To the version you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With