OSVersionExt.NetStd 3.0.1

dotnet add package OSVersionExt.NetStd --version 3.0.1
NuGet\Install-Package OSVersionExt.NetStd -Version 3.0.1
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.NetStd" Version="3.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OSVersionExt.NetStd --version 3.0.1
#r "nuget: OSVersionExt.NetStd, 3.0.1"
#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.NetStd as a Cake Addin
#addin nuget:?package=OSVersionExt.NetStd&version=3.0.1

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

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 net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OSVersionExt.NetStd:

Package Downloads
Marrow.XPlat.Desktop

Cross platform (desktop and mobile) application framework for .NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 149 3/17/2024

Updated project to .NET Standard 2.0 and tested with .NET 8.0