Environment.OSVersion Property

Definition

Gets the current platform identifier and version number.

C#
public static OperatingSystem OSVersion { get; }

Property Value

The platform identifier and version number.

Exceptions

This property was unable to obtain the system version.

-or-

The obtained platform identifier is not a member of PlatformID

Remarks

Environment.OSVersion returns an OS version that may be incorrect when an application runs under Windows compatibility mode. For more information, see GetVersionExA function remarks.

In .NET 5 and later versions, Environment.OSVersion returns the actual OS version in compatibility modes specified by the application manifest. For more information, see Environment.OSVersion returns the correct operating system version.

To identify the operating system platform, for example, Linux or Windows, you can use the RuntimeInformation.IsOSPlatform method.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1