Using the mono Runtime bundle to create an installation package to get C # desktop applications out of the NET Framework

Source: Internet
Author: User
Tags gtk mscorlib ole

Before Xamain was acquired, the cargo monodroid.exe was a bundle of bindings ... Helpless configuration environment complex, failed to achieve ... It's OK to have mono running. No, no, Madeleine.

Run the C # program independently (running from the. NET framework, running green)

Blog Category:

    • dotnet
. netwinformc#

My niche, I'm afraid.



I feel that Ms's. NET scheme is actually very good. C #, in the popular words, "very good"!

However, the. NET version is numerous. and the. NET framework Framework is large. Dragging a big. NET Framework is always frustrating.

I also met this depressing question.

Look for it on the Internet. Find another. NET Framework alternative. Mono.


The Mono2.10.2 version supports. NET 2.0 to 4.0 versions.

Download back after installation, I was silly to actually have 336M. And Mono's incredibly way is the command line. Still makes people very depressed.

Forget it, since it's installed. Look for information.

Finally saw the work of the predecessors of the crystallization.

Mono does not have much library resources to run a C # program.

As long as the C:\Program Files\mono-2.10.2\bin directory. (The C:\Program files\mono-2.10.2 directory is the root directory)


Lib\mono\.net version number \mscorlib.dll. I'm using the. NET 2.0 version here.

The necessary library files under the Lib\mono\gac\ directory. WinForm program as long as these 5 libraries on the line.

Each library file has its own. NET version number. If you are using. NET 2.0 then that directory can be deleted, if you want to ask why there is no 3.0, 3.5 library. The answer is that 3.0 and 3.5 use a 2.0 library. and 1.0 of the library because of the age, Mono2 has not supported. If necessary, you can download the earlier version of Mono.

In addition, I found a. mdb file with the same name under the library file.

The. mdb file deletion has no effect on the program. So it's all erased.

After the layers are deleted, the last few files are added up to 8M more points. And the procedure is not a problem. Perfect operation!

When the software is released with RAR compression, the program is only more than 3M. It's perfect!

But how do I know. What libraries do I need to use for my program?

The answer is: I don't know. To remember which libraries to use for the program is too tired. I'm not going to remember it. I have a lazy way. Create a new folder and put the unchanging files in the first place. The mono.exe,mono-2.0.dll,lib\mono\.net version number under the Bin directory is \mscorlib.dll. Finally, copy all the library files from mono under LIB\MONO\GAC. Run the compiled C # program. Now can start the crazy delete, encountered cannot delete the file, the rest is our program to use the library. This method is simple and efficient, and the test is unpleasant.

But then there's the problem, mono, that nasty command line. And what if someone's computer has a. NET Library installed? Isn't it better to use MS's own. NET? So I took a look at the mono website and wrote a. NET boot program with the C and Windows APIs. The. NET version can be selected according to the settings, and if the client computer already has a user-specified version installed, then the MS. NET is preferred, and if it does not exist, the mono boot program is used.

This bootloader uses Config.ini as the configuration file.

c#_version=2.0//.net version number, a total of 4 values: 2.0, 3.5, 4.0C, 4.0F

C#_appname=mybooks.exe//Pre-launch application name

This bootloader is compiled with VS 2008 under 32-bit XP. Because it is written with the Windows API, there is no additional library. So theoretically the 32-bit system should be able to use, 64-bit never tried. This bootstrapper tests both. NET 2.0 projects and. NET 4.0 projects. This program calls the Mono-2.0.dll directly. So the Mono.exe is useless. Here is my test project, run Monologin.exe directly. I am still satisfied with the effect. Also Welcome to Exchange!

Attachment Download:
C # boot project. RAR 3.17MB

    • 9af63fe1c40580238a33d62f27b0ef3020110801150801.rar (3.2 MB)
    • Download number of times: 847
    • View Picture Attachments

Previously there is a C # version and iOS version (support to download student list, name and other features, the version is not on the App Store) of the Auxiliary Assistant to help the school teachers to submit results to the academic system (University of the web version), has been planning to use MFC to write a VC + + version can be convenient in the not installed net The framework of the computer used, a few days ago to see an article on why to use mono, since the Unity3d game (mono kernel) can be packaged separately from the NET Framework, then my assistant will be able to teach. But in the online search, the Chinese information is very small, there is no specific technical details of the article (Let the C # program run independently (run from the. NET framework, green running) is my migration after the completion of the tutorial to read the article, my ideas and he is not the same, I used Mkbundle).

Although the function of auxiliary Assistant is relatively simple, but there is more technical content than Hello World. I didn't have a problem with Hello world when I was testing my package, and I was able to get away from the NET Framework, but if there were more complex features and code and a third-party class library, I didn't have a problem. Actually in my transplant process did encounter a lot of problems, this is a simple test Hello World transplant can not solve. So I write down this document after I have solved the problem.

First of all, the function of the Auxiliary Assistant (due to work reasons can not release the program code), simple point is to import the Excel score table and directly submitted to the educational system page, for a clear list of the following

1 Import Excel Score table

2 Submit to web educational Administration system

3 Visual Interface operation

The appropriate technology used

1 use System.Data.Oledb to access Excel and put the contents into System.Data.DataSet

2 Use the System.Net.HttpWebRequest analog educational system login (the system uses cookieless mode, so you need to first access the URL generated in the SessionID), and then fill in the course related information, simulation post submission, using System.Text.Regu Larexpressions's regular expression gets all the student lists and generates new post information based on the contents of the dataset, again using post to submit to the educational system.

3 Using WinForm window form

Related software

WINDOW7 Professional 64bit


NET 2.0/3.5/4.0 Framework

Mono 2.10.6

GTK 2.12

MonoDevelop 2.8.2

Now, let's talk about my specific process.

1 First Use mono migration Analyzer (MoMA) to check if the existing code can be ported to Mono. My code check passed, but the subsequent process found that access to Excel features an error, for reasons that follow. Personal feeling MoMA is not very reliable.

2 use mono to compile the source of the Auxiliary assistant. I use the Monodeveloper tool here, and of course I can use a mcs.exe command-line compiler like csc.exe. However, since MonoDevelop does not have a WinForm designer, and WinForm is WIN32 technology, compatibility is not very good under Linux, Mono recommends using the third-party form technology of gtk# to do the UI, I am here in order to use Monodeveloper WinForm code with GTK rewrite, used for one hours, code layering is better, relatively easy to peel. Of course, if you're used to Csc.exe's command-line approach, and your post-transplant program only runs under Windows, you can use Mcs.exe and don't need GTK rewrite (not trying this way, it should work, and if any of your friends have relevant experience, please let me know).

Using MonoDevelop requirements to install mono and GTK, it is important to note that MonoDevelop can choose to compile with the NET Framework or mono, and at first I didn't notice I was using net under MonoDevelop The framework compilation runs successfully, and it is always problematic to run under mono after packaging, and the error message is always empty, wasting a lot of time.

3 Select Mono under MonoDevelop, run failed after compiling successfully, report Libgda error, explain the cause of the problem the OLE DB under Mono should be encapsulated Libgda, and Mono DB supports SQL Server,oralcle, Mysql,sqllite, Excel is not supported, and as for why Excel is not supported, it is simple that Excel is actually accessed through COM (this is Microsoft's, *nix not supported). The solution is not to use OLE DB, so swap with CodePlex on the Exceldatareader, support Mono,ok.

4 MonoDevelop Runtime System.Net.HttpWebRequest error when runtime is normal and packaged. At run time found that HttpWebRequest does not work, even simple httpwebrequest.create (beginning to suspect that the cookie container and URL path problems, are excluded, the pain process is not a table). The solution is to package the Machine.config file together.

See issue with embedding Machine.config actually we can find the relevant HttpWebRequest configuration information from machine.config, the file path: Mono installation directory \etc\mono\ Mono version number \machine.config.

5 Mkbundle packaging. In fact 4 and 5 can be said together, the problem described in 4 causes me to frequently test mkbundle, trying to load different DLLs. Once suspected that the DLL was not properly included in the package, the required library lib (System.Web.dll,, GAC directory, etc.) are copied to the running directory, still error and no error prompts, crazy. This is a low-level mistake. The mono website mentions that Mkbundle is a static linker method that embed the DLL used with the application to an EXE file, and in fact Mkbundle no longer requires a class library DLL.

Mono's Mkbundle uses unix-like toolchain, so to use mkbundle under window requires installing Cygwin (the same painful process), choosing Gcc-mingw, Mingw-zlib, Pkg-config,zlib (note Do not choose GCC all installed, online said there is a problem I tried to do so, completely remove GCC only select Gcc-mingw), and then configure the Cygwin ~/.BASHRC file configuration

Export path= $PATH:/cygdrive/c/mono-2.6.1/bin
Export Pkg_config_path=/cygdrive/c/mono-2.10.6/lib/pkgconfig

Here is a reference to can not compile simple C # application with Mkbundle very detailed

In combination with my actual use of the instructions:

Mono runtime cannot be used alone with Mkbundle–o–-deps because Mkbundle has a bug, see New:mkbundle fails Due to Missing Reference to g_utf16_t O_utf8 (2.8.0, Windows XP) If you use the report directly

temp.c:in function ' main ':
Temp.c:170:warning:implicit declaration of function ' G_utf16_to_utf8 '
Temp.c:170:warning:assignment makes pointer from integer without a cast
Temp.c:185:warning:assignment makes pointer from integer without a cast
/tmp/ccgvpes0.o:in function ' main ':
/cygdrive/d/paco/jpegp4d-deploy/temp.c:170:undefined reference to
' _g_utf16_to_
UTF8 '
/cygdrive/d/paco/jpegp4d-deploy/temp.c:185:undefined reference to
' _g_utf16_to_
UTF8 '
Collect2:ld returned 1 exit status

So the combination of Mkbundle–c(2012-1-12 update executed under cmd) and Gcc-mno-cygwin(2012-1-12 update performed under Cygwin)

The following quotes from can not compile simple C # application with Mkbundle, thanks lavir the Whiolet

Execute: "mkbundle -c -o host.c -oo bundle.o --deps YourAssembly.exe <additional arguments>". Optional -z for compression. After completion, get the host.c and bundle.o files.
Remove _WIN32 from the host.c file. Add #undef _WIN32 as follows:

#ifdef _WIN32
#include <windows.h>

#ifdef _WIN32
#include <windows.h>
#undef _WIN32
Execute: "gcc -mno-cygwin -o ResultantBundle.exe -Wall host.c`pkg-config --cflags --libs mono-2 | dos2unix` bundle.o <additional arguments>". If you add -z to mkbundle Parameter, you must add --lz at this step

My supplementary

(1) Implementation Mkbundle is required embed machine.config words increase-machine.config C:\Mono-2.10.6\etc\mono\4.0\machine.config, refer to Mono project Bundles

(2) If the introduction of a third-party DLL (such as I use a third-party exceldatareader Excel.dll), should be added to Mkbundle <additional arguments> location, reference embedding a JavaScript Interpreter with Mono

Take my mkbundle as an example.

Mkbundle–c–o host.c–oo bundle.o–deps myProgram.exe Excel.dll--machine-config C:\Mono-2.10.6\etc\mono\4.0\ Nfig

Update (2012-01-12):

Mkbundle-c-o host.c-oo bundle.o--deps MonoTA.exe excel.dll-z--machine-config C:\Mono-2.10.6\etc\mono\4.0\ Nfig

6 release

The generated EXE file has been embed mono runtime, my application originally 32k, using-Z compression generated after 5MB, a bit large but acceptable. But to get rid of the NET Framework in the window execution, but also need to call several files, listed as follows (for mono4.0, I look for one, is it possible to do a tool to automatically find dependencies?)


Total 16.9MB

7 PostScript

Personally, although the process is a bit convoluted, it is perfectly possible to use mono runtime to get software out of the NET Framework, and it should be available in production environments, and hopefully mono will be better.

Using the mono Runtime bundle to create an installation package to get C # desktop applications out of the NET Framework

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.