How to port a Mono GTK# app to other platforms? - c#

I am working on a Mono GTK# desktop app written in C#. I have developed my app using the MonoDevelop IDE (v2.4.2) on a Mac (OS X v10.6.7). My app depends on the GTK# library (obviously) as well as the Mono.WebServer2 library for running a local ASP.NET server.
I have tested my app on my own Mac as well as other Macs. Everything is working out great. Now, I am interested in porting my app to other platforms (specifically, Windows 7 and Ubuntu v11.04). I have been playing around with the mkbundle command but I haven't had any luck in creating a working bundle for other platforms than Mac OS X.
Since I have tried a number of different solutions without success, I would like to hear from the Mono developers out there. What do you do to port your app to other platforms?
I have been developing C# using Visual Studio for a long time but I am new to the Mono development environment. Therefore, I would very much appreciate a detailed explanation.
Thank you very much!

It doesn't really sound like you're talking about porting, rather packaging. MonoDevelop's "Project/Create Package" function can create simple binary packages (zips etc) or source packages (source plus makefiles) but these are not the ideal form to distribute to most end-users. Some additional work is required to make a polished installer for each platform.
mkbundle bundles the Mono runtime into your app, therefore it creates binaries that are 100% platform-specific.
For Mac, the usual way to distribute an app is as an app bundle. MonoDevelop doesn't automate this for GTK# projects, but I explained how to do it on my blog.
For Ubuntu, you can distribute a zip of binaries and require that your users install Mono, GTK# and xsp. If you create a .deb package, you can embed these dependencies into the package manifest. MonoDevelop doesn't have any tools for creating deb/rpm linux packages, and I'm not familiar with the process myself.
For Windows, you can provide a zip of binaries and require that your users install .NET and GTK# for .NET. You could also create a msi installer and have it check for these prerequisites.

It sounds like you have already solved the problem of packaging for Mac.
On Ubuntu, you would want to create a .deb package that contains your app and requires other packages as dependencies (Mono, Mono.WebServer2, GTK#, GTK+, etc). The following link should get you started on building Ubuntu packages:
https://wiki.ubuntu.com/UbuntuDevelopment
For Windows, you probably already know how to build an installer if you have .NET experience. I would say that you would want to run your app on top of .NET instead of Mono. That is what the Mono team do themselves (for MonoDevelop as an example). Bring in the Mono specific bits like Mono.WebServer2 as part of your application.
Your biggest issue here will be that GTK# requires the GTK+ C libraries to be installed. Probably the easiest thing is to detect if GTK# is installed as part of the installer and ask your users to install GTK# if they need it. You are going to have to do the same detection for the .NET version you require anyway. You can get GTK# for Windows here.
I do not have great instructions for doing this but both the Banshee and MonoDevelop projects do it well. I would take a look at those projects as they will show you exactly what needs to be done.
https://github.com/mono/monodevelop
http://git.gnome.org/browse/banshee
EDIT:
I just recently realized that the code for the GTK# installer is on GitHub here.

There are is also packaging projects available in Monodevelop. you can use them.
I'm doubtful that mkbundle work well other than Linux.
Another option that open your project on other plateform (you can use Monodevelop) and build the project and use some other app to build package.

I just recently created deb package of my own .Net project written in MonoDevelop. From MonoDevelop I created a package with sources and makefiles (makefiles also generated by MonoDevelop) and then i used this guide>
http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html
to create deb package. Dependencies were mono-runtime and gtk-sharp2.

Related

Run .NET Framework on Raspberry Pi

In short, I have a console x64(/x86) C# project that is using .NET Framework 4.7.1. I need to run this project on a Raspberry Pi, some way, somehow.
I tried Mono on Raspbian. Mono worked for some of the project, but failed for two of its key libraries.
Next I tried Windows IOT. This worked well for the most part, but I couldn't run my project. After publishing it and uploading it to the Pi, it says the project is not compatible with the version of Windows I'm running. I think this might only be for .NET Core projects?
Next I tried emulating x86 through Wine on Ubuntu which was just a nightmare.
Finally I tried installing Windows Desktop on the Pi, but it lacks network adapters, and my project needs the internet to function.
What are my other options? How can I do this?
I also had a lot of problems, i have a C# application that needs to be run on arm platform. The solution I found was to make an application in Visual Studio 2012 (a Windows Form Application project), and run on RaspberryPi3 using mono:
mono myapplication.exe
In my case I use only a library of access to GPIO, and other common libraries (xml, json), so it worked fine. It would be interesting if you could quote which libraries didn't work for you.

How to run GTK# (C#) on a Mac OSX

I have a GTK# project that has been developed using C#, on Xamarin Studio, on Windows.
I can generate an .exe file for my application but I can't run this on a Mac. Is there a way for me to convert this .exe file to a .dmg / .app OR to run this .exe on a Mac without using Windows (Bootcamp)?
Note: WineBottler has not worked for my project.
You should use macpack to package the application for execution on OS X. Take a look at the manual here: http://manpages.ubuntu.com/manpages/zesty/en/man1/macpack.1.html
Here's an excerpt from that page:
macpack is a tool used to package managed assemblies
(like System.Windows.Forms or Cocoa#) that require gui
availability for deployment on Mac OS X.
macpack will prepare a OS X compatible bundle from the
provided assembly and resources. The bundle will include the
specified assembly as well as any of the provided resources (specified
with the -resource: switch).
If you have Mono installed on your Mac then the .exe compiled on Windows should run unless you've got a dependency on something that is specific to windows. Some Windows libraries have not been ported to Mono for Mac or Linux, and if you are using ILMerge (windows) or ILRepack (*nix) then you will also potentially run into issues.
You don't need to use MacPack to build an app file, you can do it manually fairly simply as long as Mono is installed on your target Mac machine. There is a structure to an .app package folder which you can build manually.
Let me know if you need any more help, Cheers, M.
You don't need anything special, provided both Gtk# and mono are installed. That said, there are not ports for many 32bits libraries, so you need to specify the architecture to use.
$ mono --arch:32 program.exe
Refer to this document:
http://www.mono-project.com/docs/about-mono/supported-platforms/osx/

How do I recompile an assembly targeting the MonoTouch profile?

On http://docs.xamarin.com/ios/about/assemblies it says that if I want to provide my code as an assembly to other MonoTouch developers: "You must recompile your source code to generate assemblies targeting the MonoTouch profile".
How do I do that?
How do I do that with Visual Studio?
How do I do that with msbuild?
I found MonoDevAssist at http://monodevassist.codeplex.com/documentation, but the instruction there said I should copy a bunch of DLLs from "your Mac". I don't have a Mac. I have installed MonoTouch for Android on my Windows machine, but I can't find a directory like the one in that description.
I have installed MonoTouch for Android on my Windows machine
What you likely have is Mono for Android which runs fine on Windows and targets Android.
MonoTouch is another product from Xamarin, targeting iOS (iPhones, iPod, iPads) and it requires a Mac computer.
Even if there's quite a bit of features shared between the two products, in general, you need to look at the documentation for the product you have.
How do I do that?
Simply re-compile your existing source code including reference(s) to the assemblies that are shipped with Mono for Android.
How do I do that with Visual Studio?
Create a new project, e.g. a library, for Mono for Android. Add your source code to the project. Add references to the SDK assemblies you requires. Rebuild your code.

MonoDevelop in windows

Is there a version of Monodevelop that runs on Windows? If so where can I get it?
MonoDevelop officially supports Windows since 2.2. You can check the what's new in Monodevelop 2.2 or download the last release.
Windows Support
Windows now Officially Supported
Windows is now an officially supported
platform for running MonoDevelop. Many
Windows specific issues have been
fixed, and some add-ins such as
debugging and subversion support have
been written specifically for Windows.
Windows Installer
We are releasing a new Windows
Installer which includes almost all
you need to run MonoDevelop. The only
external dependency is gtk#, which is
provided in a separate installer.
It looks like you can build it and run it on Windows, but I don't think there is a binary download available yet. From the docs, here:
Does MonoDevelop work on Windows?
Yes. MonoDevelop can be built and run
on Mono on Windows, although it is
still unstable and some features may
not be available. We are currently
working on a Windows installer that
will be soon be available.
There are no precompiled binaries, so you'd have to build from source. Even then, there seems to be some stability issues running MonoDevelop on Windows (see here).
Some alternatives would be SharpDevelop and/or Visual Studio Express.
Update: MonoDevelop version 2.2 and higher officially supports Windows. You can get the latest version here: http://monodevelop.com/Download
There is currently no official release of Monodevelop for windows. After researching it a little bit, it seems that MonoDevelop was started as a port of SharpDevelop which is an open source .Net IDE for windows. Perhaps you may want to look into SharpDevelop and see if it meets your needs.
You can find out more information at the SharpDevelop website:
http://www.icsharpcode.net/OpenSource/SD/
You can specifically target the Mono framework when writing apps in SharpDevelop (something you can't do with Visual Studio Express). I should have pointed this out in my answer above. From the website:
SharpDevelop has the ability to
compile your code against previous
versions of Microsoft's .NET
Framework, Microsoft's Compact
Framework or Mono (an open source
implementation of the .NET Framework
sponsored by Novell) if they are
installed.
The easiest way now to get MonoDevelop is running openSUSE Linux under VirtualBox. It's really no so hard. You will get "real" linux system with Mono & MonoDevelop running on it without any issues. Hope this helps.
There is not currently binaries available for MonoDevelop for Windows. This is because it has not been tested and is extremely buggy. Ie: you will probably not get more a minute or two of use before it crashes. Hopefully with MD 2.0 now out, this is something we will soon have time to address.
Note that you do not need MonoDevelop to use Mono. You can use the same binaries produced from Visual Studio or SharpDevelop on Mono.

mono mkbundle utility on windows

There has been a fair amount of mention of the Mono utility mkbundle which is supposed to (among other things) allow you to create a bundle (standalone .exe) with a C# project compiled with Mono. This works when I run it in Cygwin, however what I really would like to do is use the --deps option and --static option to pull in all of the dependencies and libraries so that it really is a standalone. While running the command in Cygwin, it claims that --static is unsupported under the current platform (I assume it is referring to windows). The question, then is :
Is there any way around this dilemma?
If not, what specific .dlls am I now required to carry along with my executable in order to get the thing running? It doesn't seem to be listed anywhere on the mono site.
Thanks!
http://linux.die.net/man/1/mkbundle:
On Windows systems, it it necessary to
have Unix-like toolchain to be
installed for mkbundle to work. You
can use cygwin's and install gcc,
gcc-mingw and as packages.
(sic)
There are no way to make a crossplatform app in mono with all necessary libraries included because these libraries will rely on some specific non-managed libraries.
The right way here is to create an installer (using wix for example) for your application and include a mono installer in it. So when you'll install your app the mono will be installed too. For linux you'll need to create an installer too.

Categories

Resources