System.Environment.OSVersion returns wrong version

The sequence of steps given by Nasreddine will add a manifest file, into your project.

There is another way to add a manifest. Right click project > properties > Application tab > View Windows Settings This will bring up the default manifest, which you can edit. I am using visual studio 2010 Express. From other reading the method should be similar.

For a project that uses non-windows components (I program in ESRI arc-objcets with VB.Net) there seems to be no way of adding a manifest file. The View Windows Settings button is disabled. The steps given by Nasreddine do add a Manifest file which can be edited but this cannot be incorporated into the project. I have tried many tricks: like adding as a resource (embedded and not embedded), adding it the obj > debug folder.

The kicker test was I set up a pure windows project, got a windo button comand to return the correct version string (after adding a manifest) then tried to add an non-windows component (ESRI Addin). this failed with an error message.

I am was just trying to identify the OS because the file location of required files is dependent on operating system. Hope this save others from going down this rabbit hole.


Windows 10 returns that string unless you declare that your application is compatible using a manifest. To do so add an app.manifest (right click your project -> Add -> New Item -> Application Manifest File) then uncomment the following line:

<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

You can do the same thing for Windows Vista to Windows 10. All are in the same section:

<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 Vista -->
  <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

  <!-- Windows 7 -->
  <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

  <!-- Windows 8 -->
  <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

  <!-- Windows 8.1 -->
  <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

  <!-- Windows 10 -->
  <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>

And now when you run your application it'll report the correct 10.0.*.0 version

Tags:

C#