121

I have been developing Windows Forms programs for few years. I am now looking into .NET Core (including ASP.NET Core MVC). I am searching for the new GUI desktop technology. In Visual Studio 2015 update 3 I can't see any option to make a GUI app in .NET Core.

What am I missing?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
EKanadily
  • 3,049
  • 3
  • 28
  • 29
  • You should change the angle seeing this new platform. Every existing frameworks, WPF/WinForms/UWP/GTK#/Xamarin.Mac/iOS/Android can use the code you write on .NET Core. That enables the cross platform development, just not in the way you imagine. – Lex Li Sep 23 '16 at 02:28
  • So you are saying that i can build GUIs in -for example- winforms and the back end code in .net core – EKanadily Sep 23 '16 at 03:06
  • no. Packages built on .NET Core can be added as references directly. – Lex Li Sep 23 '16 at 03:55
  • 1
    Electron is the way to go. Use asp.net behind an api. If you keep the ui logic light, you should be able to keep the most important part of the application on .net – user7558114 Feb 13 '17 at 14:05
  • 1
    As a pro tip, I would upgrade to Visual Studio 2017 (if possible) or use other tools that are available (the CLI and/or VS Code/Rider) because VS 2015 does not have access to .NET Core 2.0 tooling, which will hinder your development going forward. Even if all you're doing is experimenting with it. – Jamie Taylor Nov 16 '17 at 10:59
  • 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:46
  • 1
    I don't see the point of UWP. I want to run my .NET/WPF applications on Windows and Mac. I don't care about Hololens, xbox, surface hub et al. – Christopher Painter Mar 10 '19 at 14:26
  • check this project:[NBlink](https://github.com/anixati/NBlink) I am working on its based on [chrome devtools](https://developers.google.com/web/tools/chrome-devtools/) protocol – anixati Apr 13 '19 at 07:21
  • So normally I'd vote to close something like this as off-topic, but right now this stackoverflow question is the top Google hit for Linux Net Core GUI; thefore I give you Eto.Forms which is another Google hit. https://dotnetcoretutorials.com/2018/03/19/cross-platform-winforms-kinda/ – Joshua Jul 06 '19 at 12:59

17 Answers17

83

You were not missing anything. Microsoft shipped no reasonable way to create GUI applications directly using .NET Core until .NET Core 3, though UWP (Universal Windows Platform) is partially built on top of .NET Core.

.NET Core 3.0 includes support for Windows Forms and WPF, though it is Windows-only.

.NET 6 will include .NET MAUI, which will support Windows and macOS desktop applications and mobile applications, with Linux desktop applications supported by the community (not MS). .NET 5 will include a preview version of .NET MAUI.

For third-party cross platform options, see other answers.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
svick
  • 214,528
  • 47
  • 357
  • 477
  • 53
    omg, that is a shock! so what is the point of a cross platform framework that has no GUI ? – EKanadily Sep 22 '16 at 23:59
  • 22
    @EssamGndelee The primary point are ASP.NET Core applications. A secondary point are console applications. – svick Sep 23 '16 at 00:00
  • 3
    @ChristopherPainter Better support for cloud computing and attracting developers from platforms like Node.js are some of the reasons why .Net Core exists, yes. But that doesn't mean Microsoft cares only about those now. – svick Jul 25 '17 at 12:07
  • There seems to be no further changes in this space. Does this mean that Microsoft is implying that we should abandon Windows GUI based apps? – CYoung Nov 15 '17 at 22:34
  • 1
    @CYoung I think Microsoft's stance is that you should be using UWP for that. – svick Nov 15 '17 at 23:16
  • 1
    @svick, that would completely eliminate any cross-platform programming, which was .NET Core supposed to solve. UWP is good enough only for MS family :/ – walther Nov 16 '17 at 10:21
  • I feel like you're confusing ASP.NET Core and .NET Core here. ASP.NET Core is the web application framework, whereas .NET Core is the cross platform runtime. – Jamie Taylor Nov 16 '17 at 10:57
  • I find this answer misleading (at least today) - it tells what MS done or not done... but the question is about Visual Studio, .NET Core and Linux GUI options: - there are many, (Xamarin, Qml.NET, Gtk#, QtSharp...), available as VS Extensions, separate SDKs or NuGets... etc. i.e. trough MS-maintained delivery channels too. – hardyVeles Jan 21 '20 at 23:10
56

AvaloniaUI now has support for running on top of .NET Core on Windows, OS X, and Linux. XAML, bindings and control templates included.

E.g. to develop on macOS with Rider:

  1. Follow instructions to install the Avalonia dotnet new templates
  2. Open JetBrains Rider and from the Welcome screen,
  3. Choose New Solution → (near the top of the Templates List) → More Templates → Button Install Template...* → browse to the directory where you cloned the templates at step 1.
  4. Click the Reload Button
  5. Behold! Avalonia Templates now appear in the New Solution Templates List!
  6. Choose an Avalonia template
  7. Build and run. See the GUI open before your eyes.

GUI steps to install a dotnet new template into JetBrains Rider

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
kekekeks
  • 2,045
  • 15
  • 9
  • As an aside, anyone interested please vote for Jetbrains to include Avalonia support in Rider: https://youtrack.jetbrains.com/issue/RIDER-39247 – xendi Sep 07 '20 at 21:18
40

You could use Electron and wire it up with Edge.js resp. electron-edge. Edge.js allows Electron (Node.js) to call .NET DLL files and vice versa.

This way you can write the GUI with HTML, CSS and JavaScript and the backend with .NET Core. Electron itself is also cross platform and based on the Chromium browser.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
P. Wenger
  • 535
  • 3
  • 5
  • 7
    But why electron ? You could also just open a web-application on port X and then navigate the browser to there. Includes everything Electron can, and more because that is always the latest version of the browser - unlike Electron. If you need a specific browser version, include Google-Chrome in your distribution. – Stefan Steiger Jun 19 '17 at 15:06
  • 2
    @StefanSteiger I think that using electron and also calling the API directly through assembly will fill the gap that user will not see the app as a web app. And some devs don't want to add more communication layer using HTTP. – Brian Ng Aug 18 '17 at 06:57
  • Electron.Net looks like this is pretty simple now http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core/ – J. Allen Oct 30 '17 at 16:29
  • 1
    Electron.NET does look promising, but I'd be weary of using it in production because it forces you to open a non-secure web server on your production machine. Then again, as long as the ASP.NET Core end of the app is sat behind a properly configured reverse proxy server like IIS or nginx (or similar), then you should be safer. – Jamie Taylor Nov 16 '17 at 11:01
  • hell could just the app as an mvc/webapi, host locally on random port, and use electron interface calling local api. – Wjdavis5 Mar 14 '18 at 19:12
32

It is now possible to use Qt, QtQuick, and QML with .NET Core, using Qml.Net.

It is highly performant (not "P/Invoke chatty"), fully featured and works across Linux, OS X, and Windows.

Check out my blog post to see how it compares to the other options out there currently.

PS: I'm the author.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Paul Knopf
  • 8,943
  • 21
  • 69
  • 131
21

One option would be using Electron with JavaScript, HTML, and CSS for UI and build a .NET Core console application that will self-host a web API for back-end logic. Electron will start the console application in the background that will expose a service on localhost:xxxx.

This way you can implement all back-end logic using .NET to be accessible through HTTP requests from JavaScript.

Take a look at this post, it explains how to build a cross-platform desktop application with Electron and .NET Core and check code on GitHub.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Rui Figueiredo
  • 243
  • 2
  • 5
21

For creating a console-based UI, you can use gui.cs. It is open-source (from Miguel de Icaza, creator of Xamarin), and runs on .NET Core on Windows, Linux, and macOS.

It has the following components:

  • Buttons
  • Labels
  • Text entry
  • Text view
  • Time editing field
  • Radio buttons
  • Checkboxes
  • Dialog boxes
    • Message boxes
  • Windows
  • Menus
  • ListViews
  • Frames
  • ProgressBars
  • Scroll views and Scrollbars
  • Hexadecimal viewer/editor (HexView)

Sample screenshot

gui.cs sample output screenshot

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Kolappan N
  • 2,178
  • 2
  • 26
  • 31
6

.NET Core 3 will have support for creating Windows desktop applications. I watched a demo of the technology yesterday during the .NET Conference.

This is the only blog post I could find, but it does illustrate the point: .NET Core 3 and Support for Windows Desktop Applications

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Alex Dresko
  • 4,817
  • 2
  • 35
  • 54
5

Yes, it is possible.

.NET Core doesn't have any components for native GUI application out of the box. However, there is a NuGet package for it that is called Electron.NET, as per Gregor Biswanger's answer.

Electron is a framework that allows you to build native GUI applications on top of Node.js. Electron.NET is a NuGet package that allows you to utilise Electron and Node.js from within your .NET Core code.

The good news is that you don't have to learn JavaScript, Electron or Node.js in order to be able to use the NuGet package. JS files do run inside your application, but they get automatically generated by the build process.

All you do is build a pretty standard ASP.NET Core MVC app. The only difference is that, instead of running in the browser, it runs as a native windowed app. Besides just a few lines of code specific to the Electron.NET package, you won't need to learn anything above ASP.NET Core MVC.

This page provides a tutorial on how to use it. It also contains some links to sample code repositories.

5

I'm working on a project that might help: https://github.com/gkmo/CarloSharp

The following application is written in .NET with the UI in HTML, JavaScript, and CSS (Angular).

Enter image description here

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
guilhermekmelo
  • 589
  • 1
  • 5
  • 4
4

tl;dr - I'm not sure that it would be possible for the .NET Core developers to supply a cross-platform GUI framework.

I feel like expecting a cross-platform GUI framework to be bundled into the official tooling (especially an old version of the tooling - you mention that you're running Visual Studio 2015 update 3) for an early version of .NET Core is a little premature.

GUI frameworks are really quite heavy, and dependent on the hardware abstractions already present on the host machine. On Windows, there is generally a single window manager (WM) and desktop environment (DE) used by most users, but on the many different distributions of Linux which are supported, there are any number of possible WMs and DEs - granted most users will either be using X-Server or Wayland in combination with KDE, GNOME or Xfce. But no Linux installation ever is the same.

The fact that the open source community can't really settle on a "standard" setup for a VM and DE means that it would be pretty difficult for the .NET Core developers to create a GUI framework which would work across all platforms and combinations of DEs and WMs.

A lot of folks here have some great suggestions (from use ASP.NET Core to builds a Web application and use a browser to listing a bunch of cross-platform frameworks). If you take a look at some of the mentioned cross platform GUI frameworks listed, you'll see how heavy they are.

However, there is light at the end of the tunnel as Miguel de Icaza showed off Xamarin running naively on Linux and macOS at .NET Conf this year (2017, if you're reading this in the future), so it might be worth trying that when it's ready.

(But you'll need to upgrade from Visual Studio 2015 to Visual Studio 2017 to access the .NET Core 2.0 features.)

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Jamie Taylor
  • 1,478
  • 16
  • 41
  • no reasoning for linux variety. 1. Java runs smoothly 2. Mono runs WinForms noramlly (thou ugly) In linux you can use GTK on QT based distro and vice versa. It woul be cool to have QT bindings for .net core. – Bogdan Mart Jan 24 '18 at 14:28
  • I agree with everything that you say. However, I feel that Microsoft's approach is to provide IaaS (Infrastructure as a Service), SaaS (Software as a Service), and PaaS (Platform as a Service) via its Azure platform at the moment. It would make sense that their first party, open source, cross platform framework would point developers in that direction as a priority. The work that Azure and other companies like RHEL and Google are doing to support both ASP NET Core and .NET Core is practically legendary, and it makes sense that the priority for .NET Core seems to reflect that. – Jamie Taylor Jan 24 '18 at 19:49
3

You could develop a web application with .NET Core and MVC and encapsulate it in a Windows universal JavaScript app: Progressive Web Apps on Windows

It is still a web application, but it's a very lightweight way to transform a web application into a desktop app without learning a new framework or/and redevelop the UI, and it works great.

The inconvenience is unlike Electron or ReactXP for example, the result is a universal Windows application and not a cross platform desktop application.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
AdrienTorris
  • 7,809
  • 9
  • 30
  • 49
2

For the special case of existing Windows Forms applications:

There is a way - though I don't know how well it works.
It goes like this:
Take the Windows Forms implementation from Mono.
Port it to .NET Core or NetStandard.

Recompile your Windows Forms applications against the new System.Windows.Forms.
Fix anything that may be broken by .NET Core.
Pray that mono implements the parts you need flawlessly.
(If it doesn't, you can always stop praying, and send the Mono project a pull request with your fix/patch/feature.)

Here's my CoreFX Windows Forms repository:
https://github.com/ststeiger/System.CoreFX.Forms

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Stefan Steiger
  • 68,404
  • 63
  • 337
  • 408
2

Yes, it is possible to develop cross-platform desktop (GUI) applications, for Windows, Linux and macOS, using Visual Studio Code, .NET Core, C#, GTK 3, gtksharp and Glade as the GUI designer.

Here is how.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Teo Bebekis
  • 457
  • 4
  • 7
1

If you are using .NET Core 3.0 and above, do the following steps and you are good to go: (I'm going to use .NET Core CLI, but you can use Visual Studio too):

  1. md MyWinFormsApp optional step
  2. cd MyWinFormsApp optional step
  3. dotnet new sln -n MyWinFormsApp optional step, but it's a good idea
  4. dotnet new winforms -n MyWinFormsApp I'm sorry, this is not optional
  5. dotnet sln add MyWinFormsApp do this if you did step #3

Okay, you can stop reading my answer and start adding code to the MyWinFormsApp project. But if you want to work with Form Designer, keep reading.

  1. Open up MyWinFormsApp.csproj file and change <TargetFramework>netcoreapp3.1<TargetFramework> to <TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks> (if you are using netcoreapp3.0 don't worry. Change it to <TargetFrameworks>net472;netcoreapp3.0</TargetFrameworks>)
  2. Then add the following ItemGroup
  <ItemGroup Condition="'$(TargetFramework)' == 'net472'">
    <Compile Update="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Update="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
  </ItemGroup>

After doing these steps, this is what you should end up with:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net472'">
    <Compile Update="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Update="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
  </ItemGroup>

</Project>
  1. Open up file Program.cs and add the following preprocessor-if
#if NETCOREAPP3_1
    Application.SetHighDpiMode(HighDpiMode.SystemAware);
#endif

Now you can open the MyWinFormsApp project using Visual Studio 2019 (I think you can use Visual Studio 2017 too, but I'm not sure) and double click on Form1.cs and you should see this:

Enter image description here

Okay, open up Toolbox (Ctrl + W, X) and start adding controls to your application and make it pretty.

You can read more about designer at Windows Forms .NET Core Designer.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Mehdi Dehghani
  • 8,186
  • 5
  • 49
  • 53
1

I have been searching for this for ages now and none of the solution above are to my satisfaction.

I ended up working with https://github.com/mellinoe/ImGui.NET for now.

I can confirm it works at least across macos and win10 and claims to be compatible with linux.

Leaving this here in case it can help someone.

enter image description here

Richard Lalancette
  • 2,302
  • 21
  • 29
  • having roots game-related, this thing.. my timid guess it just redraws whole thing frame by frame? or (don't you know?) it updates just elements had to be updated/redrawn? would be cool if so.. – jungle_mole Jan 20 '21 at 00:52
  • 2
    That's correct. Each frame is processing all elements. I believe there is a cache in place if nothing changes. Been using this to create after effect plugins and it's pretty sweet. It does have a few weaker points. – Richard Lalancette Jan 22 '21 at 16:35
1

It will be available using .NET 6: https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-1/

But you can already create WinForms applications using netcore 3.1 and net 5 (at least in Visual Studio 2019 16.8.4+).

Create winforms app sample

UI Constructor available

Zhuravlev A.
  • 314
  • 3
  • 9
0

Windows Forms (and its visual designer) have been available for .NET Core (as a preview) since Visual Studio 2019 16.6. It's quite good, although sometimes I need to open Visual Studio 2019 16.7 Preview to get around annoying bugs.

See this blog post: Windows Forms Designer for .NET Core Released

Also, Windows Forms is now open source: https://github.com/dotnet/winforms

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
A. Niese
  • 304
  • 1
  • 11