Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Mkbundle: bundle Mono with applications


  • Please log in to reply
12 replies to this topic

#1 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 15 June 2009 - 03:45 AM

Mkbundle: bundle Mono with your applications

Did you ever wonder why you need .NET Framework or Mono installed to run your program? Well, it would be much more handy if you could distribute your applications without nagging your clients to install additional frameworks, is it not? So here we are. Lets bundle a .NET-based application with Mono, so you don't need Mono, or .NET installed to run it. :)

Prepare an environment

First you need to install newest Mono and Cygwin. Installing Mono is very straightforward so you cannot screw up anything. When you start installing Cygwin, go into Full view, then please include 4 additional packages. These are: gcc, mingw, mingw-zlib and zlib.

Now you need a command prompt. Both Mono and Cygwin create shortcuts for command prompts on your desktop, but you need to combine them into one. Here is a batch that does it for me. You may need to change it, if you have other Mono version for example.

echo Mono version 2.4 Build 6
echo Prepending 'C:\PROGRA~1\Mono-2.4\bin' to PATH
PATH=C:\PROGRA~1\Mono-2.4\bin;%PATH%

chdir C:\cygwin\bin
bash --login -i

Bundle an application with Mono

So we are now in a command prompt, running this Cygwin mode. Notice that this is not a DOS prompt anymore, and "dir" won't work anymore. To list files use linux command "ls". The folder you are browsing now is like the one below. Arek is a username.
C:\cygwin\home\Arek

Browse to this folder with your explorer. Now you copy 2 files into this folder. 1st is your application exe and 2nd is the file Mono.dll (2MB) that you can find in your Mono folder.
C:\Program Files\Mono-2.4\bin

For some reason the whole procedure does not work with long file names, so rename your application exe. It should comply with this old DOS 8.3 naming.

Lets go back to command prompt. You need only 1 command to bundle your application, and here is some explanation.

mkbundle is a program within Mono package | -o Bundled1.exe specifies how the Mono-bundled exe will be named | Winform1.exe says what will be included, Mono libraries will be included anyway | --deps is necessary although I am not sure what it does | -z will compress the output exe a lot

mkbundle -o Bundled1.exe Winform1.exe --deps -z

So now you got your Bundled1.exe, which contains your own app along with Mono itself. You should not need Mono nor .NET to run it. Notice that it will be 4MB or more in size. Those bundled exes are not lightweight.

Thank the author for his work

If you enjoyed reading my tutorial, please +rep me. You can also send me a cookie. :)
  • 5

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 15 June 2009 - 04:15 AM

Very cool!

Out of curiosity, does this process create an .exe that can run in Windows, or only in Cygwin? Is there a version of Mkbundle that runs under Windows?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 15 June 2009 - 04:21 AM

This was a much needed tutorial! Being able to bundle the libraries you need so the user doesn't have to install any third party software is always great. I'm guessing that if it works with Mono on Windows it will work flawlessly with Mono on Linux?

+rep

Edited by Jordan, 19 June 2009 - 05:14 AM.

  • 0

#4 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 15 June 2009 - 04:32 AM

The Mono-bundled executable runs (presumably) without Cygwin, without Mono, and without .NET Framework. I do not have another system to confirm it, but I assume it works without those without any problems. Note that some components may not be bundleble, possibly Managed DirectX or GTK#.

(Jordan) I do not have any linux, but it would be a logical assumption. Notice that Cygwin is a Windows port, so any linux could have gcc and zlib already installed.
  • 0

#5 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 15 June 2009 - 06:20 AM

Will you send me a test bundle via email so that I can try it on Linux?
  • 0

#6 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 15 June 2009 - 06:44 AM

Here is some Mono-bundled application, with simple WinForms gui. Inside you can find the source code, a build, and a Mono-bundled build. Everyone feel free to give it a try.
Mono-bundled test application.zip

For some reason I cannot upload the zip into this thread. I get a database error.
  • 0

#7 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 15 June 2009 - 06:47 AM

Thanks, I'll give it a try. You can't upload it because it is so big.

Your organization's Internet use policy restricts access to this web page at this time.


Reason:

The Websense category "Games" is filtered.


URL:

Real Family Guy Fans: Which Family Guy Character Are You? - Family Guy Quiz _campaign=CT3K&utm_source=mediafire


I'll have to download at home.
  • 0

#8 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 297 posts

Posted 15 June 2009 - 10:44 AM

awesome, got to try this out, thanks Arek
+rep
  • 0

#9 marwex89

marwex89

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2857 posts

Posted 16 June 2009 - 07:19 AM

Very interesting, man +rep
  • 0
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#10 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 19 June 2009 - 02:42 AM

Thank you all for the rep. I very much appreciate it! :)
  • 0

#11 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 19 June 2009 - 05:21 AM

The bundle package does not work with Linux and utterly fails. :(
Your source code ran fine with Mono, however. You state "based on .NET Framework 3.5" but isn't mono only equal to .NET 2.0?
  • 0

#12 ArekBulski

ArekBulski

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 480 posts

Posted 19 June 2009 - 05:38 AM

I cannot say I fully understand how Mono works. Look at this page, they state that their C# compiler supports C# 3.0 language. Is it not C# 3.0 only available in .NET 3.0 and higher? CSharp Compiler - Mono

From my understanding I can say that mkbundle worked on my pc. And mono-bundled exe worked well on my pc, as well. So it must be working properly ...right?
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download