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
  • Dark Arc
    link
    fedilink
    English
    79 months ago

    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?

    • @[email protected]OP
      link
      fedilink
      29 months ago

      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
        link
        fedilink
        English
        29 months ago

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

  • @[email protected]
    link
    fedilink
    69 months ago

    The closest I got was by just using avalonia. I had to use winforms for my uni and convincing my teachers to allow my team to use avalonia was not easy. Avalonia is not even remotely similar to winforms. You can try setting up a VM, but I understand that it is not a real solution. I found some docs for an old version of mono which referenced some of the winforms API, but I had no luck running it.

    • @[email protected]OP
      link
      fedilink
      29 months ago

      Well, I might try my luck with convincing my teachers to let us use avalonia but I’m not sure it will oucome to anything good. At this point I might as well use a VM for this, as I already had a VM for SolidWorks set up.

  • AggressivelyPassive
    link
    fedilink
    69 months ago

    The “Win” in Winforms stands for Windows, capital W. It’s simply not available for Linux.

      • @breadsmasher
        link
        English
        109 months ago

        From the FAQ

        A small driver is required for each operating system supported. Currently we have drivers for: X Window System Win32 Window System macOS Window System

        so I think you’re right

      • @cbarrick
        link
        English
        1
        edit-2
        9 months 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.

  • @[email protected]
    link
    fedilink
    69 months ago

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

  • @[email protected]
    link
    fedilink
    49 months 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.

  • @[email protected]
    link
    fedilink
    English
    4
    edit-2
    9 months ago

    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
      link
      29 months ago

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

  • @mvirts
    link
    29 months ago

    Maaaybe try an older visual studio install under wine?

  • @[email protected]
    link
    fedilink
    1
    edit-2
    9 months ago

    I know it’s possible. I’ve used a keepass client on Linux that required Winforms; I think it was keepassx.

    Mono was how I got it to work.

    • @[email protected]OP
      link
      fedilink
      1
      edit-2
      9 months ago

      well, mono in itself seems to work and I have successfully built the hello world winforms program using mono, but the monodevelop IDE won’t seem to work at all, which would make coding harder than it should be.
      I’ve also seen things online saying that monodevelop is half dead, so I don’t have much hope about this