VS 写入对最新安装的 .NET Core SDK WinForms 程序集的引用,而不是最低版本
我正在为.NET 6编写一个WinForms控件。该项目的目标框架设置为.NET 6.0。事实证明,当我在几个月前安装的最新 VS 2022 (17.1.1) 中编译项目时,VS 总是在编译的 DLL 中写入对 WinForms 程序集 v6.0.2 的引用:
我可以解释这一点,因为 6.0.2 是我的电脑上安装的 .NET 6.0 SDK 的最新版本,但为什么其他引用的程序集(如 System.Collections)不会发生这种情况或者 System.Data.Common?
我想将编译的 DLL 中 WinForms 程序集的确切版本指定为 6.0.0,以便可以在安装了任何 .NET 6 运行时(6.0.1、6.0.3、6.1.0 等)时启动 DLL )。我没有找到办法做到这一点。我尝试了 csproj 文件中的 global.json 和 RuntimeFrameworkVersion 键(另请参阅 这个问题),但这没有帮助。
有办法解决我的问题吗?
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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了解决方案。问题出在 .NET SDK 6.0.2 中:
6.0.2 SDK 更新损坏了 WinForms 应用
在这里找到了对我有帮助的解决方案:
Issue build with Windows 桌面 6.0.2
我所需要的只是将以下设置添加到 csproj 文件中:
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: