Home > database >  VS writes references to the latest installed .NET Core SDK WinForms assemblies instead of the lowest
VS writes references to the latest installed .NET Core SDK WinForms assemblies instead of the lowest

Time:03-16

I am writing a WinForms control for .NET 6. The target framework for this project is set as .NET 6.0. It turned out that when I compile the project in the latest VS 2022 (17.1.1) installed a couple of months ago, VS always writes references to the v6.0.2 of WinForms assemblies in the compiled DLL:

enter image description here

I can explain this because 6.0.2 is the latest version of the .NET 6.0 SDK installed on my pc, but why this does not happen for other referenced assemblies like System.Collections or System.Data.Common?

I want to specify the exact version for the WinForms assemblies in the compiled DLL as 6.0.0 to make it possible to launch the DLL with any .NET 6 runtime installed (6.0.1, 6.0.3, 6.1.0, and so on). I did not find a way to do this. I tried global.json and the RuntimeFrameworkVersion key in the csproj file (see also this question), but this did not help.

Is there a way to solve my problem?

CodePudding user response:

I found a solution myself. The problem was in .NET SDK 6.0.2:

6.0.2 SDK update has broken WinForms apps

A solution that helped me was found here:

Issue building with Windows Desktop 6.0.2

All what I needed is to add the following setting to the csproj file:

<ItemGroup>
  <FrameworkReference
    Update="Microsoft.WindowsDesktop.App.WindowsForms"
    TargetingPackVersion="6.0.0" />
</ItemGroup>
  • Related