【问题标题】:VS2022 'Forms' does not exist in the namespace system.windows命名空间 system.windows 中不存在 VS2022 'Forms'
【发布时间】:2022-07-07 04:12:07
【问题描述】:

根据其他答案,我尝试添加项目参考。我打开参考管理器找到 System.Windows.Forms 并添加它,但项目参考显示“未找到项目”。那么如何添加引用呢? enter image description here

enter image description here

【问题讨论】:

  • 看起来你有一个控制台模板。尝试使用 WinForms 模板创建一个新项目。
  • 根据您的问题标签,您从 2010 年开始专门使用 C# 4.0?
  • 这里是 .NET-6.0,而不是 C# 4.0。我设置了错误的标签。
  • 在解决方案资源管理器中,右键单击项目并选择Edit Project File,然后添加<UseWindowsForms>true</UseWindowsForms> 并更改<TargetFramework>net6.0-windows</TargetFramework>(如果不同)。重建。

标签: c# .net visual-studio winforms .net-6.0


【解决方案1】:

正如 Jimi 的评论所暗示的,您不能直接引用 System.Windows.Forms.dll,因为它是运行时的一部分。相反,将以下内容添加到您的项目文件中:<UseWindowsForms>true</UseWindowsForms> 并确保将目标框架设置为 <TargetFramework>net6.0-windows</TargetFramework>(而不仅仅是 net6.0),因为 Windows 窗体仅在 Windows 上受支持。

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 2022-01-11
    • 2011-10-02
    • 2014-03-04
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多