/langversion (C# Compiler Options)

Causes the compiler to accept only syntax that is included in the chosen C# language specification.

Syntax

/langversion:option  

Arguments

option
The following values are valid:

Option Meaning
default The compiler accepts all valid language syntax that it can support. Default
ISO-1 The compiler accepts only syntax that is included in ISO/IEC 23270:2003 C# (1.0/1.1) ISO1
ISO-2 The compiler accepts only syntax that is included in ISO/IEC 23270:2006 C# (2.0) ISO2
3 The compiler accepts only syntax that is included in C# 3.0 or lower CS3
4 The compiler accepts only syntax that is included in C# 4.0 or lower CS4
5 The compiler accepts only syntax that is included in C# 5.0 or lower CS5
6 The compiler accepts only syntax that is included in C# 6.0 or lower CS6
7 The compiler accepts only syntax that is included in C# 7.0 or lower CS7
latest The compiler accepts all valid language syntax that it can support. Latest

Remarks

Metadata referenced by your C# application is not subject to /langversion compiler option.

Because each version of the C# compiler contains extensions to the language specification, /langversion does not give you the equivalent functionality of an earlier version of the compiler.

Additionally, while C# version updates generally coincide with major .Net Framework releases, the new syntax and features are not necessarily tied to that specific framework version. While the new features will definitely require a new compiler update that is also released alongside the C# revision, each specific feature has its own minimum .Net API or common language runtime requirements that may allow it to run on downlevel frameworks by including NuGet packages or other libraries.

Regardless of which /langversion setting you use, you will use the current version of the common language runtime to create your .exe or .dll. One exception is friend assemblies and /moduleassemblyname (C# Compiler Option), which work under /langversion:ISO-1.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Properties page.

  2. Click the Build property page.

  3. Click the Advanced button.

  4. Modify the Language Version property.

For information about how to set this compiler option programmatically, see LanguageVersion.

See Also

C# Compiler Options
Managing Project and Solution Properties

C# Language Specification

C# Language Specification Reference : .NET Foundation
C# 1.0/1.1 ISO/IEC 23270:2003 Information technology -- C# Language Specification : ISO Catalogue
C# 2.0 ISO/IEC 23270:2006 Information technology -- C# Language Specification : ISO Catalogue
C# 2.0 c042926_ISO_IEC_23270_2006(E).zip ISO/IEC 23270:2006 in PDF format : ISO Freely Available Standards
C# 3.0 CSharp Language Specification.doc C# Language Specification Version 3.0 : Microsoft Corporation
C# 4.0 Ecma-334.pdf Standard ECMA-334 4th Edition
C# 5.0 CSharp Language Specification.docx C# Language Specification Version 5.0 : Microsoft Corporation
C# 6.0 README.md C# Language Specification Version 6 - Unofficial Draft : .NET Foundation
C# 7.0 (not currently available)

Minimum compiler version needed to support all language features

Default, ISO1: Microsoft Visual Studio/Build Tools .Net 2002 or bundled .Net Framework 1.0 compiler
ISO2: Microsoft Visual Studio/Build Tools 2005 or bundled .Net Framework 2.0 compiler
CS3: Microsoft Visual Studio/Build Tools 2008 or bundled .Net Framework 3.5 compiler
CS4: Microsoft Visual Studio/Build Tools 2010 or bundled .Net Framework 4.0 compiler
CS5: Microsoft Visual Studio/Build Tools 2012 or bundled .Net Framework 4.5 compiler
CS6: Microsoft Visual Studio/Build Tools 2015
CS7, Latest: Microsoft Visual Studio/Build Tools 2017