2

I'm developing .net core console application. I want to alert to user when want to exit application. Like below;

 MessageBox.Show("Contiue or not", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) == DialogResult.No)
    Application.Exit();

But I can't add System.Windows.Forms referance to the my project. I'm getting this error.

 Error  CS0234  The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)    

Is that possible to show Message Box on .net core Console Application?

Mert DEMIRKIRAN
  • 342
  • 2
  • 14
  • https://stackoverflow.com/questions/1119841/net-console-application-exit-event maybe this helps – Muammer Jan 24 '20 at 14:52
  • 2
    Per the [porting instructions](https://docs.microsoft.com/dotnet/core/porting/winforms), changing the SDK to `Microsoft.NET.Sdk.WindowsDesktop` and adding `true` will make this work. (The output type has to be left to `Exe` if you want a console application.) Note that it remains inherently a bad idea to do GUI calls from a console app, of course, even ignoring the gratuitous added platform incompatibility (this only works on Windows). – Jeroen Mostert Jan 24 '20 at 15:05

0 Answers0