我有一个控制台应用程序,我只想在某个时候显示MessageBox
.
我找到一个页面,该页面声明我可以通过添加对程序集的引用来完成此操作.然而,仅仅添加using System.Windows.Forms
是不起作用的(CS02348:它不存在于名称空间中,我可能缺少程序集引用).
然而,我似乎只能将COM引用添加到我的项目.当我寻找一种显示组装面板的方法时,我发现this page似乎表明我应该已经拥有它.
根据this tutorial,我应该在C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App
中手动浏览和查找.
我试着用C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.2\System.Windows.Forms.dll
和C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.13\System.Windows.Forms.dll
.对于这两个参数,我得到错误CS1705:
错误CS1705具有标识的程序集‘System.Windows.Forms’ ‘System.Windows.Forms,版本=7.0.0.0,区域性=中性, PublicKeyToken=b77a5c561934e089‘使用’系统运行时, 版本=7.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a‘ 它的版本高于引用的程序集"System.Runtime" 身份为‘System.Runtime,版本=6.0.0.0,区域性=中性, Public KeyToken=b03f5f7f11d50a3a‘
我刚刚删除了手动导入的System.Windows.Forms.dll,我的*.csproj
文件如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="RandomLibrary">
<HintPath>RandomLibrary.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
我需要它留在LTS的6.0版本中.
为什么我没有这个装配卡舌? 如何添加对System.Windows.Forms的引用?为什么我在版本6.0.13和版本7.0.2中收到相同的消息?