5

I'm currently making a bot for a discord server with Discord.NET and I'd like to create a WinForm for this instead of a console. Is there a way to implement WinForms to a .NET Core app?

Floern
  • 33,559
  • 24
  • 104
  • 119
Tom
  • 194
  • 1
  • 1
  • 8
  • We may not need to soon, as Miguel de Icaza showed off Xamarin running naively on Linux and MacOS at .NET Conf this year (https://channel9.msdn.com/Events/dotnetConf/2017/K111), so it might be worth trying that when it's ready. – Jamie Taylor Nov 16 '17 at 11:27
  • 1
    In the last Microsoft Build event they announce news about .NET Core 3. _"The highlight of .NET Core 3 is support for Windows desktop applications, specifically Windows Forms, Windows Presentation Framework (WPF), and UWP XAML."_ You can see more about it [here](https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/) – Rui Fernandes Aug 13 '18 at 08:44
  • https://stackoverflow.com/a/60621422/187650 – juFo Mar 11 '20 at 16:27

4 Answers4

24

Starting from .NET Core 3.0, you can create Windows Forms applications using .NET Core.

VS 2019

The project template is available in VS 2019.

VS 2017

You need to have Visual Studio 2017 Update 15.8 or higher.

  1. Install Visual Studio 2017 Update 15.8 or higher
    [Visual Studio download site.]
  2. Install the latest .NET Core 3.0 SDK
    [daily build (latest changes, but less stable) or preview (more stable, recommended)].

  3. Open command prompt and run the following command to create the project:

    dotnet new winforms -o MyWinFormsApp
    
  4. To build and run the project, you can go to the directory in which the project is created and open MyWinFormsApp.csproj using Visual Studio, build and run it.

    You can also run the following commands if you prefer to build and run from command line:

    cd MyWinFormsApp
    dotnet build
    dotnet run
    

Note

  • Project Template: The project template is available in VS 2019.
  • Designer: Along with GA release of .NET Core 3.0, Windows Forms Designer Preview 1 has also been released and can be used in VS 2019. Also starting from Visual Studio 16.5 Preview 1 and by release of .NET CORE 3.1, Visual Studio has built in support for designer. Take a look at this post. But keep in mind, in this release, many controls aren’t yet supported in designer.

Related links

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • does VS 2019 preview 1 has template and support by form designer? – Falco Alexander Dec 09 '18 at 07:38
  • 2
    @FalcoAlexander No, but by taking a look at the [WinForms on .NET Core Roadmap](https://github.com/dotnet/winforms/blob/master/roadmap.md), it seems the final release (or the update after the final release) of VS2019 will include them. – Reza Aghaei Dec 09 '18 at 07:48
  • 1
    @FalcoAlexander [Windows Forms Designer Preview 1](https://devblogs.microsoft.com/dotnet/introducing-net-core-windows-forms-designer-preview-1/) – Reza Aghaei Oct 02 '19 at 09:56
  • 1
    @FalcoAlexander [Updates to .NET Core Windows Forms designer in Visual Studio 16.5 Preview 1](https://devblogs.microsoft.com/dotnet/updates-to-net-core-windows-forms-designer-in-visual-studio-16-5-preview-1/) – Reza Aghaei Jan 23 '20 at 13:17
1

Edit: Since I wrote this back in September 2017, the reality has changed. As of the .NET Core SDK 3, Windows Forms support has been added back in. It does not have the platform independance of many other parts of .NET Core and converting between .NET Framework and .NET Core WinForms code needs a conversion tool. But it is there.

No, not really. .NET Core is a specific selection of classes from the larger .NET Framework, which includes Windows Forms. Windows Forms is one of the things they (had to) cut out to make the smaller .NET Core.

Last I looked, .NET Core had support for UWP (a followup to WPF), Xamarin and ASP.Net 5 (Core version). UWP and maybe Xamarin would be suitable for Desktop applications:

Christopher
  • 9,634
  • 2
  • 17
  • 31
  • But does it work on Windows 7, No (If this is a first requirement) – Anirudha Gupta Mar 13 '18 at 07:03
  • @Adrian: I am not quite sure what you are saying. "Does it work on Windows 7?" It is really a non-question as .NET Core does not have WindowsForms at all. The classes were left out during the Framework -> Core translation. If you need Windows Forms, you havbe to use the .NET Framework. I think Mono had a number of WindowsForms classes ported as well. But you will find close to nothing Windows Forms related in .NET Core. – Christopher Mar 13 '18 at 11:34
  • I means UWP support .net Core but UWP can't support #Windows7 – Anirudha Gupta Mar 13 '18 at 11:36
  • Today I installed Skype on Windows 10 (run as Windows 7) and I see the same UI (as win10 UWP). Maybe Microsoft have something internally to produce UWP app's Windows 7 version. – Anirudha Gupta Mar 13 '18 at 11:36
  • UWP is just the .NET Core Brother of WPF. Both use XAML as design language. UWP is a bit more restrictive in Application Rights, but that is it. Something you designed for UWP should easily compile or be convertible to WPF. – Christopher Mar 13 '18 at 11:38
  • Christopher, I need to check these things, I mostly used ASP.NET MVC for web-apps – Anirudha Gupta Mar 13 '18 at 11:39
1

.Net core 3 preview is released which includes WPF and Win Forms support. You can use it with Visual studio 2019 preview which can publish Win Forms platform independently and self contained.

0

I know this is an old post, but I am currently in the process of doing this I can tell you it is very possible now. Hopefully when I'm done it catches on, basically I'm creating a simple user interface to pass off to a D&D DM so he can administer the game easily.

Like I said I know this is an old post and probably no one cares, but I figured I'd throw it out there that it can be done.

  • 1
    While it's recently become true that an official release of .NET Core supports WinForms, this answer really doesn't provide much useful information beyond saying it's possible. One would hope an answer would mention specific versions needed or steps to take to get this working, like [@RezaAghaei's answer](https://stackoverflow.com/a/53690334/150605) does, so the reader is not left having to research that themselves. – Lance U. Matthews Oct 24 '19 at 21:24
  • 1
    Yeah my bad, what I have done thus far is very simple, but is a nice place to start. I have made a public repository with the project for anyone to use. I figured out the basics following a youtube series found here-> https://www.youtube.com/watch?v=sdFK7TSjgNk . The repository is available here - > https://github.com/djmaclachlan/Discord-Bot – SomeNerdAtWork Oct 28 '19 at 14:06