OSVersionExt 3.0.0

dotnet add package OSVersionExt --version 3.0.0
NuGet\Install-Package OSVersionExt -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OSVersionExt" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OSVersionExt --version 3.0.0
#r "nuget: OSVersionExt, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OSVersionExt as a Cake Addin
#addin nuget:?package=OSVersionExt&version=3.0.0

// Install OSVersionExt as a Cake Tool
#tool nuget:?package=OSVersionExt&version=3.0.0

Properly detect Windows version in C# .NET – even Windows 11

Allows you to determine the correct Windows version, since System.Environment.OSVersion.Version in .NET Framework and .NET Core until version 4.8 respectively 3.1 returns wrong results on Windows 10. It works starting with Windows 2000 and also on Windows 11/Windows 10/Server 2022/Server 2019/Server 2016 right away.

Also available on Nuget: https://www.nuget.org/packages/OSVersionExt/

<img src="images/windows10-version-demo.png">

Console.WriteLine($"Windows version: " +
    $"{OSVersion.GetOSVersion().Version.Major}." +
    $"{OSVersion.GetOSVersion().Version.Minor}." +
    $"{OSVersion.GetOSVersion().Version.Build}" +
    $"");

Console.WriteLine($"OS type: {OSVersion.GetOperatingSystem()}");
Console.WriteLine($"is workstation: {OSVersion.IsWorkstation}");
Console.WriteLine($"is server: {OSVersion.IsServer}");
Console.WriteLine($"64-Bit OS: {OSVersion.Is64BitOperatingSystem}");

if (OSVersion.GetOSVersion().Version.Major >= 10)
{
    Console.WriteLine($"Windows Release ID: {OSVersion.MajorVersion10Properties().ReleaseId ?? "(Unable to detect)"}");
    Console.WriteLine($"Windows Display Version: {OSVersion.MajorVersion10Properties().DisplayVersion ?? "(Unable to detect)"}");
    Console.WriteLine($"Windows Update Build Revision: {OSVersion.MajorVersion10Properties().UBR ?? "(Unable to detect)"}");
}

List of detected operating systems

The class can return the OS as an enum.

    public enum OperatingSystem
    {
        Unknown,
        Windows2000,
        WindowsXP,
        WindowsXPProx64,
        WindowsHomeServer,
        WindowsServer2003,
        WindowsServer2003R2, 
        WindowsVista,
        WindowsServer2008,
        WindowsServer2008R2,
        Windows7,
        WindowsServer2012,
        Windows8,
        Windows81,
        WindowsServer2012R2,
        WindowsServer2016,
        WindowsServer2019,
        Windows10,
        Windows11,
        WindowsServer2022
    }
Operating system tested remarks
Windows 11 yes
Windows Server 2022 yes
Windows 10 yes 21H2 (build 19044), 21H1 (build 19043), 2009/20H2 (build 19042), 2004 (build 19041), 1909 (build 18363), 1903 (build 18362), 1809 (build 17763) - all x64
Windows Server 2019 yes
Windows Server 2016 yes
Windows Server 2012 R2 yes
Windows 8.1 yes x64
Windows 8 -
Windows 7 yes x86
Windows Server 2008 R2 yes x64
Windows Server 2008 -
Windows Vista -
Windows Server 2003 R2 yes
Windows Server 2003 -
Windows Home Server -
Windows XP 64-Bit Edition -
Windows XP -
Windows 2000 -

Target framework

NET Framework 4.6.2 (as one of the checks calls Environment.Is64BitOperatingSystem). Yet, you can inject your own environment provider, which runs on lower versions.

Technical information

Please refer to https://www.prugg.at/2019/09/09/properly-detect-windows-version-in-c-net-even-windows-10/

Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on OSVersionExt:

Repository Stars
freezy/dmd-extensions
A toolbox for virtual pinball dot matrix displays.
Version Downloads Last updated
3.0.0 2,176 8/19/2023
2.0.0 16,251 9/4/2022
1.0.1 1,927 1/30/2022

Added Windows 11 and Server 2022 support; Breaking change: enum OperatingSystem has been changed for certain Windows editions