this post was submitted on 16 Mar 2024
11 points (100.0% liked)

Programming

19098 readers
131 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

Hi Lemmings, I wondered if anyone had successfully created a C# project that uses winforms on linux.
I just can't figure out how to do it.
I use Arch and have full dotnet 6 and 8 packages; but I can't dotnet new winforms as the template seems to not exist.
I also have installed mono and monodevelop installed, but even the simplest solution (Console App) can't load correctly (currently I have /usr/share/dotnet/sdk/8.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5) : error MSB4062: The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly /usr/share/dotnet/sdk/8.0.102/Sdks/Microsoft.NET.Sdk/targets/../tools/net472/Microsoft.NET.Build.Tasks.dll. Invalid Image Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. but there were different similar errors before, these errors.
I don't really want to boot up a VM every time I have to code on that project, but I'm starting to feel desperate about this.

TLDR: How does one create and work on a WinForms C# project with linux ? Any suggestions are welcome

Some clarifications for future readers :

  • It is for a school group project; winforms in imposed, which sadly won't let me go with Avalonia
top 17 comments
sorted by: hot top controversial new old
[–] fuzzzerd@programming.dev 2 points 1 year ago

Check out Avalonia. It's like cross platform WPF. Not winforms, but still pretty good and easy to start with.

[–] JakenVeina@lemm.ee 1 points 1 year ago* (last edited 1 year ago) (1 children)

I know folks in the C# Discord have talked about getting WinForms to work on Linux, you could post a question there. But unless you're specifically dealing with maintaining some legacy app, you should not be using WinForms, much less on Linux. Avalonia or Xamarin are definitely the way to go if you're making something new and want cross-platform desktop support.

Protip if you do go down that route: Tutorials tend to ignore the fact that you don't have to use XAML to make anything in these frameworks. You should. But if it's more comfortable for you to write WinForms-style imperative code that you're used to, you 100% can, the APIs are not significantly different.

[–] Curdie@lemmy.world 2 points 1 year ago

I can definitely Avalonia for cross platform UI. It's amazing.

[–] lysdexic@programming.dev 1 points 1 year ago

OP,

Here's a friendly reminder that programming.dev has a community dedicated to .NET: !dotnet@programming.dev

[–] douglasg14b@programming.dev 1 points 1 year ago

.Net 8 will work on Linux just fine. But winforms will not, it's specifically a legacy windows-only UI framework.

You're going to have to jump through some incredible hoops to get it to work on Linux. Which are definitely not part of your normal curriculum.

[–] agressivelyPassive@feddit.de 1 points 1 year ago (1 children)

The "Win" in Winforms stands for Windows, capital W. It's simply not available for Linux.

[–] Kissaki@programming.dev 0 points 1 year ago (1 children)

Official source (emphasis mine)

Welcome to the Desktop Guide for Windows Forms, a UI framework that creates rich desktop client apps for Windows.

[–] cbarrick@lemmy.world 1 points 1 year ago* (last edited 1 year ago)

Of course Microsoft implemented it "for Windows".

The Mono project implements many of the .Net APIs in a portable way for other operating systems, including an implementation of WinForms on X11.

OP specifically mentioned that they were using Mono.

[–] Dark_Arc@social.packetloss.gg 0 points 1 year ago (1 children)

This isn't an answer to your question.

I'm just curious, why winforms? Is there something that they do really well that you're just dying to use on Linux? Trying to get a legacy application working? Familiarity?

[–] nope@jlai.lu 0 points 1 year ago (2 children)

none of that; it's a school project which imposed winforms, else I'd have found some thing that would have worked for my linux

[–] Dark_Arc@social.packetloss.gg 1 points 1 year ago

I'd recommend using a VM in that case and calling it a day.

[–] eveninghere@beehaw.org 0 points 1 year ago* (last edited 1 year ago) (1 children)

That syllabus likely assumes Windows. C# on non-Windows is not impossible, but it's going to require effort infeasible for school projects like that one. As you're facing it, C#'s packages were originally not meant to be used cross-platform, and god only knows the amount of problems that lie ahead. That clearly didn't occur to the teacher's head while they designed the course.

[–] douglasg14b@programming.dev 2 points 1 year ago (1 children)

C# on non-Windows is not impossible, but it's going to require effort infeasible for school projects like that one.

You mean winforms (The windows specific UI) on non-Windows? Otherwise this is incredibly misleading, and plain wrong.

C# in non windows is the norm, the default even, these days. I build, compile, and run, my C# applications in linux , and have been for the last 5+ years.

[–] eveninghere@beehaw.org 0 points 1 year ago* (last edited 1 year ago) (1 children)

Not talking about winforms in that quoted part. I thought that was obvious.

I don't buy the second paragraph, especially as the phrasing is so loose it can mean anything.

Edit: overall I think this will result in a typical internet conversation that turns into "lmao that's the weakest argument I've ever seen!" "you're so pathetic!" etc. etc.

[–] Lucky@programming.dev 3 points 1 year ago (1 children)

Dotnet core (now just dotnet) was a full rebuild of the framework specifically for cross platform support so they could get more enterprise cloud hosting on azure, running everything on Linux

Modern C# is built for first class Linux support for everything except UI

[–] eveninghere@beehaw.org 1 points 1 year ago* (last edited 1 year ago)

Nope. There are nuggets that lack ARM binaries, for example. And I've had enough troubles on macOS therefore.

[–] mvirts@lemmy.world 0 points 1 year ago

Maaaybe try an older visual studio install under wine?