6

I'm using Fedora 27 as my Operating System, and I'm wondering if I could get the Xamarin toolset working on it to create cross platform apps with an IDE like monodevelop, VS Code or Rider.

I heard Xamarin get's new templates for Xamarin.Forms for Linux, but I can't find any recent development news about that.

  • No, you cannot. Xamarin tooling is currently only supported on Windows and Mac. You have to hack yourself or wait till Xamarin releases Linux support. – Lex Li Feb 08 '18 at 20:33

2 Answers2

10

Yes, as of mid-2018, it is somewhat possible to develop a Xamarin.Forms app under MonoDevelop on Linux. I successfully managed to do it.

Basically, you need to have at least two things:

  • A shared library project, containing all the cross-platform Xamarin.Forms code and Xaml files. For some reason, on Linux this library project have to be compiled with .NET Core toolchain and not Mono toolchain (otherwise there is some GTK issues at runtime later on). The target framework is .NET Standard 1.0 or .NET Standard 2.0, and the main dependency is the NuGet package "Xamarin.Forms".
  • A Mono/GTK# platform-specific project for Linux, containing all the platform specific code: initialize GTK and Xamarin.Forms.Platform.GTK backend, and start the Xamarin.Forms code. The dependencies are the NuGet package "Xamarin.Forms.Platform.GTK", references to locally installed GTK# of your linux distribution (gtk-sharp, atk-sharp, etc...), and obviously a reference to the shared library project. Note that only GTK2 is supported and not GTK3.

The shared library project may be developed with MonoDevelop, Visual Studio, or JetBrains Rider. Note that with MonoDevelop, there is no XAML designer... so this is easier to do the design stuff with Visual Studio on Windows.

The platform specific project may be developed using MonoDevelop or Rider on Linux.

Here is a picture of the project structure under MonoDevelop:

ProjectStructure

  • There is a "HelloWorldXamarin" library project. It uses the .NET Core toolchain targeting .NET Standard 1.0, and have a dependency to NuGet package "Xamarin.Forms"
  • There is a "HelloWorldXamarin_Linux" project. It uses the Mono toolchain targeting Mono/GTK# for Linux, and have dependencies to GKT# and HelloWorldXamarin library, as well as dependency to NuGet package "Xamarin.Forms.Platform.GTK". You can see the platform specific code on the right.

And a picture of the result:

Result

So you can now develop cross-platform Xamarin.Forms GUI applications for Windows,Mac,Linux,Android,iOS...

Gabriel Cuvillier
  • 3,617
  • 1
  • 28
  • 35
  • I agree this answer is a little bit complex, and that using MonoDevelop is not convenient for this. That could explain the downvotes, even if it is actually working for real ;) – Gabriel Cuvillier Feb 17 '19 at 14:25
  • 2
    I couldn't add the GTK to my cross-platform project. in the Nuget manager the GTK versions available are all higher than 3.0.+. `Package 'Xamarin.Forms.Platform.GTK 4.7.0.968' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. ` – Carla Camargo Jun 19 '20 at 14:33
1

Yes you can and how well it will work on Fedora I'm not sure, but it looks like development is still in progress for the GTK Backend on Linux. For more information, there's a Github repo here that shows how far along it is and how you can try it yourself.

Nick Peppers
  • 3,161
  • 23
  • 27