简体   繁体   English

无法从 WPF 项目中删除 Windows.Forms 参考

[英]Can't Remove Windows.Forms reference from WPF Project

I added <UseWindowsForms>true</UseWindowsForms> to my .NET 6.0 WPF project to use some dialog classes, and then removed it after deciding to use the WindowsAPICodePack instead.我将<UseWindowsForms>true</UseWindowsForms>添加到我的 .NET 6.0 WPF 项目以使用一些对话框类,然后在决定改用WindowsAPICodePack后将其删除。 But the project is still behaving as if I were referencing System.Windows.Forms .但是该项目仍然表现得好像我在引用System.Windows.Forms Intellisense offers the Namespaces/Types, and System.Windows.Forms.Analyzers and System.Windows.Forms.Analyzers.CSharp show up in the Analyzers section of Solution Explorer. Intellisense offers the Namespaces/Types, and System.Windows.Forms.Analyzers and System.Windows.Forms.Analyzers.CSharp show up in the Analyzers section of Solution Explorer.

However, it no longer shows up under the Frameworks section of Solution Explorer.但是,它不再显示在解决方案资源管理器的框架部分下。 The <ImplicitUsings> also stopped including the namespace. <ImplicitUsings>也停止包含命名空间。

How do I get rid of the DLL references?如何摆脱 DLL 引用? I've tried running "Remove unused references" and it didn't help.我试过运行“删除未使用的引用”,但没有帮助。

After my test, the Forms reference can be deleted.Please check if the steps below are consistent with yours.经过我的测试,Forms参考可以删除。请检查以下步骤是否与您的一致。

1.Delete all codes and references related to Forms in the project. 1.删除项目中与Forms相关的所有代码和引用。

    using System.Windows.Forms;
    ...

    System.Windows.Forms.MessageBox.Show("hello");

2.Right-click the project and select Unload Project, then right-click the project and select Edit Project File. 2.右击工程和select卸载工程,然后右击工程和select编辑工程文件。

3.Delete <UseWindowsForms>true</UseWindowsForms> and save the csproj file. 3.删除<UseWindowsForms>true</UseWindowsForms>并保存csproj文件。

4.Right-click the project and select Reload Project,then rebuild the project. 4.右击工程和select Reload Project,然后重建工程。

5.You could see that all references to Forms in the Microsoft.WindowsDesktop.AppWPF directory have been deleted. 5.可以看到Microsoft.WindowsDesktop.AppWPF目录下对Forms的所有引用都被删除了。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM