将mono运行时和你的程序打包在一起,window下桌面程序部署新篇章
浏览(5318)Mono转载自http://www.joebest.org/2011/09/mono-and-mkbundle-on-windows.html
A problem for a fair few Mono and .NET developers is "what if the user doesn't have Mono or .NET installed?" You can bootstrap the .NET installer into an .msi installer, but if you really need to just zip up a few files and send them to someone, and have your application just work, then you might need mkbundle.
Mkbundle is a great tool included in the Mono framework, which allows you to embed the Mono runtime with your application, into a single executable. On OSX you can just use MonoMac (especially if you want to distribute something on the Mac App Store), but on Windows we'll need to crank up the good ol' command line!
Right, the first thing to say, is that on Windows, mkbundle is sort of broken (at least in Mono 2.10.5 which I'm using), the code is pretty straightforward, so I might have a go at patching it up if I get some time in the next few months, I've never contributed to an open-source project before, first time for everything. Anyway, here's the list of workarounds I had to use to get an application to bundle and run:
- Install Mono to a path with no spaces (mine is C:\Mono-2.10.5)
-
Install Cygwin, adding the following packages:
- gcc-mingw
- mingw-zlib
- pkg-config
- nano
- Start up Cygwin and type nano .bashrc
-
At the end of the file add:
- export PKG_CONFIG_PATH=/cygdrive/c/Mono-2.10.5/lib/pkgconfig
- export PATH=$PATH:/cygdrive/c/Mono-2.10.5/bin
- Restart Cygwin
- Copy the Mono executable to C:\Cygwin\<user>\home
- Copy C:\Mono-2.10.5\etc\mono\4.0\machine.config to the home directory alongside the executable
-
Type the following into cygwin:
- mkbundle -c -o host.c -oo bundle.o --deps --machine-config machine.config YOUR_APPLICATION.exe -z
- nano host.c
- Scroll down to find:
#include <windows.h>
#endif
Change it to:
#ifdef _WIN32
#include <windows.h>
#endif
#undef _WIN32
-
Save the file by hitting CTRL + o, and then enter -
Finally, to compile the intermediate files into a final executable, type the following into Cygwin:
- gcc -mno-cygwin -o BundledExecutable.exe -Wall host.c `pkg-config --cflags --libs mono-2|dos2unix` bundle.o -lz
- You'll need to copy mono-2.0.dll and zlib1.dll from C:\Mono-2.10.5\bin to wherever your final executable will be, other than that, you should be good to go.
That should do the trick, but this specific series of steps might not work (or be unnecessary) in later releases of Mono.
打包后文件会在运行时在8m左右而且无需安装 直接绿色文件解压即可运行 对。net的部署来说简直就是福音 下图是打包后的程序
标签: