This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Add os supported versions to host #4700
Merged
vitek-karas
merged 6 commits into
dotnet:master
from
vitek-karas:AddOsSupportedVersionsToHost
Oct 31, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9587a2d
Add a manifest to dotnet.exe with supported version of Windows
vitek-karas 667f9c0
Only add the manifest on Windows
vitek-karas 255b569
Add automated test for the dotnet.exe manifest and supported OSes
vitek-karas cdda072
Add a comment about inability to test apphost for now.
vitek-karas 4dc8922
Make the test only run on Windows as this is Windows only feature.
vitek-karas 357f049
Fix missing dispose in tests.
vitek-karas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> | ||
| <application> | ||
| <!-- A list of the Windows versions that this application has been tested on and is | ||
| is designed to work with. Uncomment the appropriate elements and Windows will | ||
| automatically selected the most compatible environment. --> | ||
|
|
||
| <!-- Windows 7 --> | ||
| <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /> | ||
|
|
||
| <!-- Windows 8.1 --> | ||
| <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /> | ||
|
|
||
| <!-- Windows 10 --> | ||
| <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> | ||
| </application> | ||
| </compatibility> | ||
| </assembly> | ||
149 changes: 149 additions & 0 deletions
149
src/test/Assets/TestProjects/TestWindowsOsShimsApp/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace TestWindowsOsShimsApp | ||
| { | ||
| public static class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine("Hello World!"); | ||
| Console.WriteLine(string.Join(Environment.NewLine, args)); | ||
| Console.WriteLine($"Framework Version:{GetFrameworkVersionFromAppDomain()}"); | ||
|
|
||
| #if WINDOWS | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not needed, but I personally would prefer to keep it - makes it more explicit. I don't like code which doesn't run, but also doesn't work at all. |
||
| Version osVersion = RtlGetVersion(); | ||
| if (osVersion == null) | ||
| { | ||
| Console.WriteLine("Failed to get OS version through RtlGetVersion."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($"Detected true OS version: {osVersion.Major}.{osVersion.Minor}"); | ||
| if (OsVersionIsNewerThan(osVersion)) | ||
| { | ||
| Console.WriteLine($"Reported OS version is newer or equal to the true OS version - no shims."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($"Reported OS version is lower than the true OS version - shims in use."); | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| private static string GetFrameworkVersionFromAppDomain() | ||
| { | ||
| return System.AppDomain.CurrentDomain.GetData("FX_PRODUCT_VERSION") as string; | ||
| } | ||
|
|
||
| #if WINDOWS | ||
| [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
| internal struct OSVERSIONINFOEX | ||
| { | ||
|
|
||
| internal uint dwOSVersionInfoSize; | ||
| internal uint dwMajorVersion; | ||
| internal uint dwMinorVersion; | ||
| internal uint dwBuildNumber; | ||
| internal uint dwPlatformId; | ||
| [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] // | ||
| internal string szCSDVersion; | ||
| internal ushort wServicePackMajor; | ||
| internal ushort wServicePackMinor; | ||
| internal ushort wSuiteMask; | ||
| internal byte wProductType; | ||
| internal byte wReserved; | ||
| } | ||
|
|
||
| [Flags] | ||
| enum ConditionMask : byte | ||
| { | ||
| VER_EQUAL = 1, | ||
| VER_GREATER = 2, | ||
| VER_GREATER_EQUAL = 3, | ||
| VER_LESS = 4, | ||
| VER_LESS_EQUAL = 5, | ||
| VER_AND = 6, | ||
| VER_OR = 7 | ||
| } | ||
|
|
||
| [Flags] | ||
| enum TypeMask : uint | ||
| { | ||
| VER_MINORVERSION = 0x0000001, | ||
| VER_MAJORVERSION = 0x0000002, | ||
| VER_BUILDNUMBER = 0x0000004, | ||
| VER_PLATFORMID = 0x0000008, | ||
| VER_SERVICEPACKMINOR = 0x0000010, | ||
| VER_SERVICEPACKMAJOR = 0x0000020, | ||
| VER_SUITENAME = 0x0000040, | ||
| VER_PRODUCT_TYPE = 0x0000080 | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] | ||
| internal unsafe struct RTL_OSVERSIONINFOEX | ||
| { | ||
| internal uint dwOSVersionInfoSize; | ||
| internal uint dwMajorVersion; | ||
| internal uint dwMinorVersion; | ||
| internal uint dwBuildNumber; | ||
| internal uint dwPlatformId; | ||
| internal fixed char szCSDVersion[128]; | ||
| } | ||
|
|
||
| [DllImport("ntdll.dll", ExactSpelling=true)] | ||
| private static extern int RtlGetVersion(ref RTL_OSVERSIONINFOEX lpVersionInformation); | ||
|
|
||
| [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| private static extern bool VerifyVersionInfo(ref OSVERSIONINFOEX lpVersionInfo, TypeMask dwTypeMask, ulong dwlConditionMask); | ||
|
|
||
| [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] | ||
| private static extern ulong VerSetConditionMask(ulong dwlConditionMask, TypeMask dwTypeBitMask, ConditionMask dwConditionMask); | ||
|
|
||
| internal unsafe static int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) | ||
| { | ||
| osvi = new RTL_OSVERSIONINFOEX(); | ||
| osvi.dwOSVersionInfoSize = (uint)sizeof(RTL_OSVERSIONINFOEX); | ||
| return RtlGetVersion(ref osvi); | ||
| } | ||
|
|
||
| internal static Version RtlGetVersion() | ||
| { | ||
| if (RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) == 0) | ||
| { | ||
| return new Version((int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion); | ||
| } | ||
| else | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| internal static bool OsVersionIsNewerThan(Version osVersion) | ||
| { | ||
| // check if newer than | ||
| OSVERSIONINFOEX osv = new OSVERSIONINFOEX() | ||
| { | ||
| dwOSVersionInfoSize = (uint)Marshal.SizeOf<OSVERSIONINFOEX>(), | ||
| dwMajorVersion = (uint)osVersion.Major, | ||
| dwMinorVersion = (uint)osVersion.Minor | ||
| }; | ||
|
|
||
| var conditionMask = 0uL; | ||
| conditionMask = VerSetConditionMask(conditionMask, TypeMask.VER_MAJORVERSION, ConditionMask.VER_GREATER_EQUAL); | ||
| conditionMask = VerSetConditionMask(conditionMask, TypeMask.VER_MINORVERSION, ConditionMask.VER_GREATER_EQUAL); | ||
|
|
||
| if (VerifyVersionInfo(ref osv, TypeMask.VER_MAJORVERSION | TypeMask.VER_MINORVERSION, conditionMask)) | ||
| { | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/test/Assets/TestProjects/TestWindowsOsShimsApp/TestWindowsOsShimsApp.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(NETCoreAppFramework)</TargetFramework> | ||
| <RuntimeIdentifier>$(TestTargetRid)</RuntimeIdentifier> | ||
| <OutputType>Exe</OutputType> | ||
| <RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion> | ||
| <DefineConstants Condition="'$(OS)' == 'Windows_NT'">WINDOWS;$(DefineConstants)</DefineConstants> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
59 changes: 59 additions & 0 deletions
59
src/test/HostActivationTests/GivenThatICareAboutWindowsOsShims.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.WindowsOsShims | ||
| { | ||
| public class GivenThatICareAboutWindowsOsShims : IClassFixture<GivenThatICareAboutWindowsOsShims.SharedTestState> | ||
| { | ||
| private SharedTestState sharedTestState; | ||
|
|
||
| public GivenThatICareAboutWindowsOsShims(SharedTestState fixture) | ||
| { | ||
| sharedTestState = fixture; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MuxerRunsPortableAppWithoutWindowsOsShims() | ||
| { | ||
| if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| // Manifests are only supported on Windows OSes. | ||
| return; | ||
| } | ||
|
|
||
| TestProjectFixture portableAppFixture = sharedTestState.PortableTestWindowsOsShimsAppFixture.Copy(); | ||
|
|
||
| portableAppFixture.BuiltDotnet.Exec(portableAppFixture.TestProject.AppDll) | ||
| .CaptureStdErr() | ||
| .CaptureStdOut() | ||
| .Execute() | ||
| .Should().Pass() | ||
| .And.HaveStdOutContaining("Reported OS version is newer or equal to the true OS version - no shims."); | ||
| } | ||
|
|
||
| // Testing the standalone version (apphost) would require to make a copy of the entire SDK | ||
| // and overwrite the apphost.exe in it. Currently this is just too expensive for one test (160MB of data). | ||
|
|
||
| public class SharedTestState : IDisposable | ||
| { | ||
| private static RepoDirectoriesProvider RepoDirectories { get; set; } | ||
|
|
||
| public TestProjectFixture PortableTestWindowsOsShimsAppFixture { get; set; } | ||
|
|
||
| public SharedTestState() | ||
| { | ||
| RepoDirectories = new RepoDirectoriesProvider(); | ||
|
|
||
| PortableTestWindowsOsShimsAppFixture = new TestProjectFixture("TestWindowsOsShimsApp", RepoDirectories) | ||
| .EnsureRestored(RepoDirectories.CorehostPackages) | ||
| .PublishProject(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| PortableTestWindowsOsShimsAppFixture.Dispose(); | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.