dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.12k stars 4.7k forks source link

.Net Core 3.0 preview returns 6.2 for OSVersion on Win10 #28375

Closed SteveL-MSFT closed 4 years ago

SteveL-MSFT commented 5 years ago

.Net Core 2.1 returned 10.0.x for Environment.OSVersion. However, .Net Core 3.0 Preview 009817 returns 6.2.x. This breaks some PSCore6 tests as we're trying to move to 3.0.

danmoseley commented 5 years ago

Are you sure?

c:\d\2b>type Program.cs | find /i "write"
              Console.WriteLine($"Corelib: {typeof(string).Assembly.CodeBase}");
              Console.WriteLine($"OSVersion: {Environment.OSVersion.ToString()}");

c:\d\2b>dotnet run -f netcoreapp2.1
Corelib: file:///C:/Program Files/dotnet/shared/Microsoft.NETCore.App/2.1.6/System.Private.CoreLib.dll
OSVersion: Microsoft Windows NT 6.2.9200.0

c:\d\2b>dotnet run -f netcoreapp2.2
Corelib: file:///C:/Program Files/dotnet/shared/Microsoft.NETCore.App/2.2.0/System.Private.CoreLib.dll
OSVersion: Microsoft Windows NT 6.2.9200.0

c:\d\2b>dotnet run -f netcoreapp3.0
Corelib: file:///C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.0.0-preview-27205-02/System.Private.CoreLib.dll
OSVersion: Microsoft Windows NT 6.2.9200.0

c:\d\2b>csc Program.cs && Program.exe
Microsoft (R) Visual C# Compiler version 2.10.0.0 (b9fb1610)
Copyright (C) Microsoft Corporation. All rights reserved.

Corelib: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
OSVersion: Microsoft Windows NT 6.2.9200.0
SteveL-MSFT commented 5 years ago

@danmosemsft seeing different results in PSCore6

# PSCore6.2 on .NET Core 2.1
[System.Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.18312.0 Microsoft Windows NT 10.0.18312.0
# PSCore 6.2 built on .NET Core 3.0 as netcoreapp3.0
[System.Environment]::OSVersion

Platform ServicePack Version    VersionString
-------- ----------- -------    -------------
 Win32NT             6.2.9200.0 Microsoft Windows NT 6.2.9200.0

This is same machine where PSCore6.2 is netcoreapp21 on the first one and netcoreapp30 in the second.

SteveL-MSFT commented 5 years ago

I'll dig into this further to see what's happening on the PSCore6 side

danmoseley commented 5 years ago

Probably a windows compat shim ("version lie"?) being applied. Either to Powershell or to us. What does Win32 give within your process?

daxian-dbw commented 5 years ago

It might be worth mentioning that we applied an application manifest (https://github.com/PowerShell/PowerShell/blob/master/build.psm1#L468) to make OSVersion return the correct value for pwsh, and as is shown, it works in .NET Core 2.1.

Here is the manifest file: https://github.com/PowerShell/PowerShell/blob/master/assets/pwsh.manifest

SteveL-MSFT commented 5 years ago

Thanks @daxian-dbw perhaps 3.0 isn't respecting that compatibility setting?

danmoseley commented 5 years ago

As far as I know we know nothing about compat shims. We call Win32 (::GetVersionExW) and display what it tells us. I would verify your manifest is being applied to your process.

SteveL-MSFT commented 5 years ago

Using the sysinternals tool sigcheck I can view the application manifest is embedded in pwsh.exe. Interestingly, the trustInfo section is in the 3.0 built pwsh.exe, but missing the compatibility section which is in the 2.1 built pwsh.exe. Will continue to investigate.

danmoseley commented 5 years ago

It sounds like that's the issue, it might make sense to close this now or move it to the Powershell repo.

SteveL-MSFT commented 5 years ago

The issue appears that the compatibility section of the application manifest doesn't get embedded in a 3.0 built exe https://github.com/dotnet/core-sdk/issues/267