Skip to content

Instantly share code, notes, and snippets.

@devlead
Created April 1, 2015 14:02
Show Gist options
  • Save devlead/d41763d293e5c6cc5f88 to your computer and use it in GitHub Desktop.
Save devlead/d41763d293e5c6cc5f88 to your computer and use it in GitHub Desktop.
Windows 10 aware app.manifest

OSVersion

In windows 8.1 Environment.OSVersion underlying Win32 GetVersionEx function changed to for compatibility reasons report latest version app is compiled for.

The code

Console.WriteLine(
    System.Environment.OSVersion
    );
  • Without 8.1 ID on 8.1
    • Microsoft Windows NT 6.2.9200.0
  • Without 10 ID on 10
    • Microsoft Windows NT 6.3.9600.0
  • With 10 ID on 10
    • Microsoft Windows NT 10.0.10049.0

Usage

If you have an app.manifest just add the <supportedOS Id/> you are missing. Otherwise just Add new item to the project, search for manifest and choose Application Manifest File with file name app.manifest

Basically your .csproj should include (should just work if you add an Application Manifest File with file name app.manifest)

  <PropertyGroup>
    <ApplicationManifest>app.manifest</ApplicationManifest>
  </PropertyGroup>

and

  <ItemGroup>
    <None Include="app.manifest" />
  </ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista and Windows Server 2008 -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>
<!-- Windows 7 and Windows Server 2008 R2 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 and Windows Server 2012 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>
<!-- Windows 8.1 and Windows Server 2012 R2 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</asmv1:assembly>
Copy link

ghost commented Apr 2, 2022

  1. see that your xml is properly formatted source.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
      <dependency> 
        <dependentAssembly> 
          <assemblyIdentity name="Microsoft.Windows.Common-Controls" 
            version="6.0.0.0" publicKeyToken="6595b64144ccf1df" 
            type="win32" processorArchitecture="*" language="*" /> 
        </dependentAssembly> 
      </dependency> 
      <application xmlns="urn:schemas-microsoft-com:asm.v3"> 
         <windowsSettings> <dpiAware      xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>                     </windowsSettings> 
         <windowsSettings> <dpiAwareness  xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness> </windowsSettings> 
         <windowsSettings> <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>                   </windowsSettings> 
         <windowsSettings> <heapType      xmlns="http://schemas.microsoft.com/SMI/2020/WindowsSettings">SegmentHeap</heapType>                 </windowsSettings> 
      </application> 
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
        <security> 
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> 
            <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
          </requestedPrivileges> 
        </security> 
      </trustInfo> 
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application> 
          <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> 
          <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /> 
          <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /> 
          <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /> 
          <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /> 
        </application> 
      </compatibility> 
    </assembly> 
  2. not having supportedOS will run your app in vista virtualization mode.

    my application is still recognising Win10 as Win6
    it might be helpful to query for the actual version using API/WMI:

@Arthanzar
Copy link

Thanks.
Sorted; I ran it again a day or two later and it worked properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment