问题
I have been developing WinForms 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?
回答1:
You were not missing anything. MS 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 Winforms and WPF, though it is Windows-only.
For cross platform options that have come up in the past 2 years, see other answers.
回答2:
You could use Electron and wire it up with Edge.js resp. electron-edge. Edge.js allows electron (node.js) to call .net dll's 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.
回答3:
It is now possible to use Qt/QtQuick/QML with .NET Core, using Qml.Net.
It is highly performant (not "pinvoke chatty"), fully featured and works across Linux/OSX/Windows.
Check out my blog post to see how it compares to the other options out there currently.
PS: I'm the author.
回答4:
AvaloniaUI now has support for running on top of .NET Core on Win/OSX/Linux. XAML, bindings and control templates included.
e.g. to develop on MacOs with Rider:
- Follow instructions to install the Avalonia dotnet new templates
- Open JetBrains Rider and from the Welcome screen,
- Choose
New Solution
-> (Near the top of the Templates List) ->More Templates
-> ButtonInstall Template...
-> browse to the directory where you cloned the templates at step 1. - Click the
Reload
Button - Behold! Avalonia Templates now appear in the
New Solution
Templates List! - Choose an Avalonia template
- Build and run. See the GUI open before your eyes.
回答5:
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 on 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
回答6:
we coded an open source solution for electron with .net core: Electron.NET. https://github.com/ElectronNET/Electron.NET
Enjoy!
回答7:
For creating console-based UI, you can use gui.cs. It is open-source (from Miguel, creator of Xamarin), and runs on .Net core on Windows, Linux & 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
回答8:
.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 does illustrate the point: https://blogs.msdn.microsoft.com/dotnet/2018/05/07/net-core-3-and-support-for-windows-desktop-applications/
回答9:
tl;dr - I'm not sure that it would be possible for the .NET Core devs 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 VS 2015 update 3) for an early version of .NET Core is a little premature.
GUI frameworks are really quite heavy, and dependant 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 ever Linux installation 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 devs 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 VS 2015 to VS 2017 to access the .NET Core 2.0 features)
回答10:
It's an old question, but yes, it is possible to develop cross-platform desktop (GUI) applications, for Windows, Linux and macOS, using VSCode, .Net Core, C#, gtk3, gtksharp and Glade as GUI Designer.
Here is how.
回答11:
You could develop a web application with .NET Core and MVC and encapsulate it in a Windows universal JavaScript app : https://docs.microsoft.com/en-us/windows/uwp/porting/hwa-create-windows
It is still a web app but it's a very lightweight way to transform a web app 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 app and not a cross platform desktop app.
回答12:
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/JS/CSS (Angular)
回答13:
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.
回答14:
Necromancing.
For the special case of existing WinForms applications:
There is a way - though I don't know how well it works.
It goes like this:
Take the WinForms implementation from mono.
Port it to .NET Core or NetStandard.
Recompile your WinForms applications against the new System.Windows.Forms.
Fix anything that may be broken by NetCore.
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 WinForms repo:
https://github.com/ststeiger/System.CoreFX.Forms
来源:https://stackoverflow.com/questions/39649976/is-it-possible-to-make-desktop-gui-application-in-net-core