how to install and use Winforms in VSCode on Linux? - c#

(.NET Core Version 3.0.103 (Commit: b7ef045669), Platform/OS: ubuntu linux 18.04-x64, Winforms branch version (date): Thu Mar 26 07:37:13 2020 -0700, VSCode 1.43.2)
I cloned current version of Winforms from Github, tried to use appropriate installation script (build.sh) but finally got only error message (I think it's a bug).
Possibly someone was more succefull?
(Even though Winforms Designer doesn't still work in VSCode on Linux as I got from documentation there should be possibility to create Windows Form Application templates from console, port existing application from .NET Framework to .NET Core and so on).
So can anyone share your experience about this?

Winforms is currently a Windows-only technology in the .NET Core runtime. I haven't seen an instance of someone circumvening this limitation.
.NET Core (and in the future .NET 5 that is built on top of .NET Core) will be the future of .NET. We are committed to support .NET Framework for years to come, however it will not be receiving any new features, those will only be added to .NET Core (and eventually .NET 5). To improve Windows desktop stacks and enable .NET desktop developers to benefit from all the updates of the future, we brought Windows Forms and WPF to .NET Core. They will still remain Windows-only technologies because there are tightly coupled dependencies to Windows APIs. But .NET Core, besides being cross-platform, has many other features that can enhance desktop applications.
The Mono Project supports Winforms, which can be run on linux, however I'm unaware of how to develop Winforms via Mono on vscode.

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.

I'm newbie to .NET. I have some doubts in understanding terminologies .What is the difference between .NET core and .NET 5?

.NET Framework only supports the Windows platform.
.NET core supports Windows, Linux, and Mac OS.
.NET Core will not support andriod and ios.
.NET 5 supports Windows,MAC OS,LINUX,Anroid and IOS.
Am i correct in all the above points?
This is not a precise answer but good for a newcomer, prone to be confused and overwhelmed by the official and exhausting information.
There are two parallell platforms.
.NET Framework
.NET Core
.NET 5 will merge those two into a single one. So .NET 5 is the next generation (sort of) of .NET Core. But it't also quite more as well. As for the supporting OS's, you're not wrong but you're not quite right, neither. It's not precisely a yes/no issue. It may support certain features of some OS differently well and corresponding to your need or not. It's a jungle and it's constantly changing.
Now, you might have specific considerations like which should you learn at the moment. On that question - you should go with .NET 5. (Unless there's a specific reason, e.g. job requirement, for you to go with .NET Core 3.x, which is the current version, or .NET Framework 4.x, which is its current dito).
You may also wonder how big is the difference between the platforms. To that, there are two answers. For me, it's humongous - basically day and night. For you, assuming the proficiency level suggested by your question, it's negligible - you won't notice even if it kicks you in the nuts. It's a good thing. You can't pick wrongly.
Another issue might be whether you will be able to deploy your product the requested way. You will be. However, picking another framework may make that easier. It also may make that harder. Bottom line is, you won't know until you're there but the general purpose frameworks will never block you.
.NET 5 is a combined platform which includes libraries and frameworks from the following:
.NET Framework
.NET Core
Xamarin
For Cross-platform based development, the .NET Core framework versions 1.0 to 3.1 covers development of web apps, windows forms apps, server based apps, mobile apps and cloud hosted apps.
ASP.NET Core is the open-source version of ASP.NET, that runs on macOS, Linux, and Windows. Versions are from 1.1 to 3.1 within .NET Core and version 5 for .NET 5.
https://dotnet.microsoft.com/learn/aspnet/what-is-aspnet-core
ASP.NET is the windows version of ASP.NET, a platform that allows development of web applications hosted on windows servers. Versions are from 1.x to 4.x.
https://dotnet.microsoft.com/apps/aspnet
The Xamarin platform (not part of .NET Core) allows cross-platform Android and IOS mobile development and is included as part of the .NET 5 platform.
https://dotnet.microsoft.com/apps/xamarin
For Windows platform based development, the .NET Framework versions 1.0 to 4.8 covers development of windows client and server applications.
https://learn.microsoft.com/en-us/dotnet/framework/get-started/overview
Due to the confusion with renaming some of the .NET Core frameworks to .NET 5 frameworks, Microsoft has kept the name "Core" in some of it's technologies.
For example, ASP.NET Core 3.1 keeps it's Core name with the new ASP.NET Core 5 framework instead of confusing it with ASP.NET 5 or ASP.NET MVC 5, which are still in use by many developers.
Another example is the .NET Framework based ORM provider Entity Framework 5, and the .NET Core based ORM provider Entity Framework Core 5, both of which keep their names to avoid confusion within the .NET 5 platform.
Depending on what your application development goals are (cross-platform, windows, mobile, server etc.) you can choose the project templates and libraries from .NET Core or .NET Framework compatible packages within .NET 5 (and beyond) that will achieve your goals.

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

Compatible with both dotnet 3.5 and dotnet 4.0

Originally it is set to use .Net3.5 for compatibility with win7. (Actually using WPF)
However when it comes to users in win8 which supports only the .Net4.0,
it is required for users to download and install .Net3.5,
which results in a terrible user experience.
Here comes my question:
How to make a software compatible with multiple .Net versions?
Actually I tried to use .Net 2.0 for the software and it goes well with both win7 and win8. However when it comes to .Net 3.5, the backward compatibility seems to be awful. However I really need some features available in 3.5, or WPF.
I don't mind if I have to build multiple binary releases, provided a auto-selection mechanism is available.
P.S. I've found a similar question at Make same app compatible for Net3.5 & 4.0#stackoverflow but got no help after reading it.
Edit
I'm using both winform and WPF. I'm using WPF for a better looking UI, however, as is nutoriously know, the webbrowser in WPF cannot render in a WPF app. So I use a winform webbrowser.
If you're making an normal WPF desktop application, just move your target framework to .Net 4 and be done with it. .Net 4 is fully supported on Windows 7 as well as Windows 8. If you don't want to have the users download an install .Net 4, include it in your setup distribution.
Make sure you don't use types that are not included in the lowest version you target!
.NET 2, 3 and 3.5 all share the same CLR, which should have the same effect on your code and expected outcome. 3.0 and 3.5 has different types as well, so watch out for that.
.NET 4.0 has a different CLR and your code might not act 100% in the same way as with the CLR 2.0.
But, why not ship with the redistributable 4.0 framework. It works on XP sp3, Vista sp1 , 7 and 8. Distributing .NET 4.0 redistributable with application

Deploying c# app - user need to install .net framework?

Hey guys - I just wrote an app using c# and ready to deploy it. Never deployed a c# app before.
I deployed it and VC# outputted a .application file, application folder, and an installer. One of my users ran the installer (Windows 7) and was prompted to download/install the .net framework - which took upwards of 10 minutes. This is not acceptable for how simple my app is.
Moreover, I will need this app to be able to run on mac osx and linux if possible. Should I have wrote this in Java instead (poor planning on my part). What are my options?
C# is compiled to bytecode that runs on the CLR, the virtual machine that's at the core of the .NET framework. So yes, you need the .NET framework to run that.
Most current versions of Windows (XP, Vista, 7, etc.) come with some version of the .NET framework pre-installed, so your users don't have to download and install it. However, you might have used a version that's not already installed on the computers of (some of) your users.
For Linux and Mac OS X there is Mono, which is an open source implementation of .NET, but it does not contain everything that Microsoft's .NET contains, so your program might not work fully on Mono.
Using Java is not a real solution in the sense that your users would need to download and install the JRE (Java Runtime Environment) to run Java programs, very similar to the .NET framework. An advantage if you'd have used Java, is that Java is much more cross-platform compatible than .NET (Microsoft has no real interest in making .NET run on anything else than Windows).
.NET apps require the .NET framework. Java apps require the JRE. Your app is simple because .NET has done a lot of the work for you. A lot of companies write desktop apps in C++, but you will have to be mindful of cross-platform issues.
Yes, with any language that compiles to run on a managed runtime (.NET or Mono CLR, Java JVM) you will need to have that runtime installed. A C# application can compile to run on Windows on the .NET CLR, or on all the platforms you mention to run on the Mono runtime instead. Alternatively, a Java application would compile to run on the Java JRE, which is also compatible with all the platforms you mention.
So with either language there is potentially this extra installation overhead, and with either language you can achieve what you want.
You'll need to have .NET installed on your client's system in order to use your application.
As for running cross-platform - depending on how your Application is written, this can be simple or difficult.
You may want to look at Silverlight. This is directly supported on OS X and works on Linux via Moonlight.
Another alternative is to use Mono to run your .NET application on other platforms.
A C# app will need an implementation of the CLR (.NET) running on the local machine in order to run. A Java app will need an implementation of the JVM so it is really no different. On Windows, I would expect most people to have a .NET install.
Take a look at the Mono project as far as running it on Linux and Mac:
http://mono-project.com/Main_Page
One thing you can consider is using an older version of the .NET framework to ensure that the greatest number of people have it installed. I would use .NET 3.5 or even 2.0 if you do not need fancy new features. That would have been installed already on Windows 7 for example.
Since the Windows 7 user had to download the framework I assume you are currently targeting .NET 4 which means you must be using Visual Studio 2010 (or an express version). Here is a link that tells you how to target a different version of the framework:
http://msdn.microsoft.com/en-us/library/bb398202.aspx
One quick note about Mono, it is an excellent cross-platform option but it does not support the Windows Presentation Foundation (WPF) GUI framework at this point. You will either have to use Windows Forms or create different front-ends for different platforms.
If you want to create a Linux GUI (also available on Windows and Mac) you can try GTK#:
http://www.mono-project.com/GtkSharp
For a Mac native GUI you can check out MonoMac:
http://mjhutchinson.com/journal/2010/06/09/monomac_in_monodevelop
An excellent IDE for cross-platform .NET development is MonoDevelop (it will read your VC# project files):
http://monodevelop.com/
Like Java, .Net languages need a runtime installed. The full .Net framework is sometimes too big for small applications, so there is a smaller version of it call the compact framework with a smaller footprint that will install and download faster. You can read about it at http://msdn.microsoft.com/en-us/netframework/aa497273.aspx. As noted by other answers most current versions of Windows come with various versions of .Net framework, so this installation may not be needed for every user.
As far as your cross platform needs go Mono allows for running .Net applications on Linux, I am not sure about running them on OSX. My assumption is you can not. Unfortunately your cross platform requirements made .Net a bad choice, and you should have gone with Java.
Other people gave you complicated answers. Well here's my simple answer. .NET framework is needed to run .NET applications and so do Java need JVM (as MCain said). Starting with Windows Vista, Microsoft includes .NET Framework built inside Windows. And in addition, .NET have versions, from 1.0 to 4.0. With Vista and Windows 7, .NET 3.5 is installed by default. I think your app is targeted for .NET 4.0 which is why a Windows 7 user needed to install .NET framework. For me, if I have to write a simple program, I'll use .NET 2.0 (later version = larger libraries, etc) so that my users (if they are Vista or Windows 7) don't have to install .NET again to run my software. You can choose which version of .NET you will target from New Project Window in Visual Studio.
You can change the target framework in the properties tab. If you start a project in VS2008 the default is .net 3.5 and for VS2010 it is .net 4.0. If you don't need the advanced features you can change your target back to 2.0 which should be available on most computers by now (I would guess far over 90%). Be sure to remove dependencies which are not available in 2.0 (like System.Linq, System.DataSet.Extensions) and the accociated imports (But the compiler will tell you what to do).

Categories