.net core cross platform desktop app - c#

I'd like to develop a cross platform desktop app by using .net Core. The app needs to be executed on linux, mac os, and windows. For that purpose, should i create a console app and put below lines in settings xml?
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;osx.10.12-x64;debian.8-x64</RuntimeIdentifiers>
</PropertyGroup>
Will it be sufficient? If so, should i write all platforms and separate by comma e.g.
win7-x32;win10-x64;...
If it is not the answer, how can i generate cross platform desktop app with .net Core?

As the other answer alludes to, .NET Core itself is cross-platform, but it doesn't offer any GUI solution. You can run console/terminal applications, as well as web applications, but not desktop applications.
As of right now, there is no official Microsoft tech that solves a multi-platform GUI. The two that I know of are Avalonia and Eto.Forms. Both have their pros and cons, and both are kinda buggy. Not in the sense that it's unusable, but in the sense that it's evolving tech, don't expect them to blow your mind right off the bat.
Guides to get you started :
Avalonia - https://docs.avaloniaui.net/
Eto.Forms - https://dotnetcoretutorials.com/2018/03/19/cross-platform-winforms-kinda/

1) Console apps in .NET core are already cross-platform.
2) For those working with a GUI, .NET core finally has a cross-platform GUI option officially supported by Microsoft called .NET MAUI
This builds on the same APIs as Xamarian Forms.
Official .NET MAUI Github Repo

If I understand your question correctly, it could be devided into two questions.
1) Howto create a cross platform .net core app
2) Howto create a cross platform .net core UI app
To answer the second (2) question: It's not possible to create cross platform apps using only .net core and microsoft libraries. What you need is a cross platform UI library with binding for all of your your target platforms. The first search result I get is Avalonia https://github.com/AvaloniaUI/Avalonia
I doubt it will be an easy task to get it working as all the alternatives seems to be experimental and/or beta. But you can certainly prove me wrong.
Good luck!

You can try electron.js instead . At present its quite difficult to build a cross platform desktop application only with .NET Core

You have many solutions for making a cross platform application with .NET Core:
Electron.NET
Avalonia
...
If you want detailed information about how to do that you should check a dedicated book who provide project samples for .NET Core 3 Here . With that you will find the most adapted UI for your app.

Related

Exporting my .NET 7 WinForms app to Linux?

For a project, I build a WinForms application using .NET 7.0. I noticed it must run on Linux so I made some research and found that it's possible to run .NET code with mono but it's not applicable to WinForms. Is there a solution to convert my project without having to make the design of the forms from scratch (like would be the case with mono development)?
Thanks.
What I tried: Installing mono and running my code. It says me that no CLI image was found.
No cross-platform desktop GUI exists in .NET out of the box.
To overcome this issue Microsoft created MAUI although it was announced Linux devices won't get official support.
Your best bet would be to migrate to Avalonia or UNO, both are great open-source, free and feature-rich frameworks built on top of .NET which works on any operating system, including Ubuntu, macOS and Windows.
Both frameworks use XAML dialect which should feel familiar for developers coming from WPF, UWP, or Xamarin Forms.
UNO can be developed using C# markup instead XAML
No XAML needed if you don’t want it – Enjoy a Flutter-like
UI development experience with C# and .NET Hot Reload
by using C# for Markup
Only .NET 7 console app runs (through .NET 7 runtime) on Linux, no WinForms, no WPF.
If you need a .NET desktop app running on Linux, and you are targeting GNOME desktop environment, you could give a try to gtk# based on mono.

What is required to run / ship a C# application on Linux?

This answer is no longer up to date.
I built a C# application using .NET core and it runs on Linux.
My question is, what libraries or existing frameworks (such as .NET core) are required to run this application on Linux or can I somehow distribute my application to multiple platforms and have it "just work".
The app I created, called ConsoleApp1 shows the following directory structure:
But I am not sure what is required to allow the binary application to work.
Does some sort of runtime need to be installed?
It depends on the Distro, and what type of c# app your building, because it probably will only work with command line apps. If, as you mention work with core, i recommend you wait for .net 5. Because it will integrate all of Microsoft's Frameworks (.net framework, .net core, mono) into one, right now the most complete one is .net framework and because it's really integrated with windows, many parts will not work with other platforms. Meanwhile, consider the Uno Platform, or as i mention wait for .net 5 which will launch November this year.
.Net 5:
https://devblogs.microsoft.com/dotnet/introducing-net-5/
Uno Platform:
Part 1:
https://www.youtube.com/watch?v=fyo2BI4rn0g&t=555s
Part 2:
https://www.youtube.com/watch?v=QQJcMsmgXuI

Net Core 3.0 and desktop applications

I just read that there is possibility to develop Windows Forms using .NET Core 3.0. Unfortunetly designer is still under development and not available. I also read that even if Windows Forms can be done using Core 3.0 that doesn't mean that it can run on either MAC or OS (same with WPF). My question is what is then the sense of it if it cannot be deployed on diffrent systems besides Windows? What type of desktop application can i really develop to be able to deploy on various systems rather than Windows forms?
That's because Microsoft seems to plan to retire the original .net and just focus on developing .netcore. My suggestion is to build application using web technologies. This way you have the best of both worlds either build web application or develop cross platform apps using something like electron.js
there are so many great apps built with electron like Vs Code or Github
There are many use cases for Windows-only desktop applications, particularly in the corporate world where applications are for internal use.
If you need a cross platform application I would suggest either a web application, or you could consider Electron.
AvaloniaUI (A cross platform XAML Framework for .NET Framework, .NET Core and Mono) would be a perfect choice if you are familiar with WPF.
There are many other frameworks to develop cross-platform desktop apps. You can checkout my github repo electron-alternatives for more cross-platform desktop development options.

Share Library between UWP App and .NET Core

What is the best practice to share a library (also C# project) between Windows UWP app and a .NET Core web app?
I have the following solution setup starting from scratch:
Solution
UWP App
Lib (With functionality I want to use in both other projects.)
.NET Core WebApp (2.2 or maybe 3.0)
As far as I could figure out, the only solution is, to create two projects for the lib, which share the same .cs files. But this feels a bit like a workaround and I am looking for a "clean(er)" way.
You can share a .NET Standard 2.0 library between those projects, see Microsoft's documentation.
Note, that you cannot use any classes specific to .NET Core or the UWP in such a project.

Programmatically change Font size in .NET Core Console App

I've been searching and searching and I can't seem to find a way to programmatically cross-platform (.NET Core) change the Font size of the .NET Core Console App.
Is this possible at all in .NET Core directly, or do I need to build a .NET Standard library myself that supports all the platforms I need to support with native code?
Thanks in advance!
There is no .NET Core support for this in the framework. Yes - you would have to build your own library to do this. At first blush, this would be non-trivial... In Windows you have both cmd and powershell shells to deal with. On Linux, there are a variety of desktop environments you might have to support to make this truly cross platform.
In the environments I'm aware of, this would have the effect of changing font for all console windows. Is this what you're trying to do?
What is the actual use case for this? Typically, users set their terminal environment up the way they want and leave it. Changing the color of the text is a more trivial endeavor.

Categories