我正在开发 .net core 控制台应用程序。当用户要退出应用程序时,我想发出提示。如下所示:
MessageBox.Show("Contiue or not", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) == DialogResult.No)
Application.Exit();
但是我无法将System.Windows.Forms引用添加到我的项目中。我遇到了这个错误。
Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
在.NET Core控制台应用程序中显示消息框是否可能?
Microsoft.NET.Sdk.WindowsDesktop
并添加<UseWindowsForms>true</UseWindowsForms>
即可使其正常工作。(如果您想要控制台应用程序,则输出类型必须保留为“Exe”)。当然,从控制台应用程序中进行GUI调用本质上仍然是一个坏主意,即使忽略了不必要的平台不兼容性(这仅适用于Windows)。 - Jeroen Mostert