You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7 Windows x64控制台应用如何添加BindingSource依赖?

.NET 7 Windows x64控制台应用添加System.Windows.Forms依赖的方法

步骤1:安装System.Windows.Forms NuGet包

System.Windows.Forms在.NET 7中以NuGet包形式提供,并非默认包含在Microsoft.NETCore.App框架内。你可以通过两种方式安装:

  • 在Visual Studio中打开「NuGet包管理器」,搜索System.Windows.Forms并安装与.NET 7匹配的7.0.x版本
  • 执行dotnet CLI命令:
    dotnet add package System.Windows.Forms
    

步骤2:修改.csproj文件的关键配置

要确保应用仅针对Windows x64平台并启用Windows Forms支持,需在项目文件中添加以下设置:

  1. 指定Windows专属目标框架:将默认的net7.0改为net7.0-windows,引入Windows平台专属API支持
  2. 锁定x64运行时:添加RuntimeIdentifier属性,明确仅针对win-x64平台
  3. 启用Windows Forms支持:添加UseWindowsForms属性并设为true

完整的.csproj示例如下:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Windows.Forms" Version="7.0.0" />
  </ItemGroup>

</Project>

验证配置

修改完成后重新生成项目,即可正常引用System.Windows.Forms.BindingSource类并使用其功能。

内容的提问来源于stack exchange,提问作者KarloX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 19:46:00