DEV Community

Shleemypants
Shleemypants

Posted on

Issues with GenerateManifests in sdk-style csproj file

As you may know, to get an accurate OS version number in .NET Framework 4.x, you need to create an app.manifest file using Visual Studio and then un-comment the Windows versions you'd like to support:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
    <!-- A list of the Windows versions that this application has been tested on
        and is designed to work with. Uncomment the appropriate elements
        and Windows will automatically select 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>
Enter fullscreen mode Exit fullscreen mode

By doing so, Visual Studio will automatically add the following property to your project (.csproj) file:

<PropertyGroup>
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
Enter fullscreen mode Exit fullscreen mode

Now you can get the correct version number:

var version = Environment.OSVersion.Version;

// Before: 6.2.9200.0
// After: 10.0.19044.0
Enter fullscreen mode Exit fullscreen mode

The Problem

While I was migrating a project to the new sdk-style project file, I noticed that the OS version number was incorrect. I was keeping the net48 Target Framework (TFM) so that wasn't the issue.

The issue was just like when the manifest file doesn't exists.

The Symptom

This was happening only when I was publishing the project using the Build > Publish menu in Visual Studio. Otherwise everything was fine.


I used the try-convert tool to migrate the project. More Info

try-convert --keep-current-tfms --no-backup
Enter fullscreen mode Exit fullscreen mode

The Fix

After hours of debugging I found out that the GenerateManifests tag in my .csproj file was causing the issue.

<GenerateManifests>true</GenerateManifests>
Enter fullscreen mode Exit fullscreen mode

I'm not exactly sure why this was happening but I'm glad that the issue has been resolved.

If you know why, please let me know in the comments.

Top comments (0)