C # Run the winform program independently (run in green instead of the. NET Framework)

Source: Internet
Author: User
Tags mscorlib

I think the Ms. Net solution is actually very good. C #. In popular words, it is "awesome "!

However, there are many. Net versions. In addition, the. NET Framework framework is very large. Dragging a large. NET Framework is always depressing.

I also encountered this depressing problem.

Find it online. Find another. NET Framework alternative. Mono.

For: http://www.go-mono.com/mono-downloads/download.html

Mono2.10.2 supports. NET 2.0 to 4.0.

After downloading and installing it, I was so stupid that I had 336 MB. In addition, Mono actually uses command line. Still depressing.

Forget it. Now that it is installed. Find information.

Finally, I saw the work of my predecessors.

Mono runs the C # program and does not need many library resources.

 

As long as the c: \ Program Files \ mono-2.10.2 \ bin directory. (The following uses the c: \ Program Files \ mono-2.10.2 directory as the root directory)

Mono.exe, mono-2.0.dll

Lib \ mono \. Net version \ mscorlib. dll. I am using. NET 2.0.

Library files in the Lib \ mono \ GAC \ directory.The winform program only needs these five databases.

 

Each library file has its own. Net version. If. NET 2.0 is used, the directory 4.0.0.0 can be deleted. If you want to ask why there are no 3.0 or 3.5 libraries. The answer is 3.0 and 3.5 use a 2.0 library. Because of the long history of 1.0 of databases, mono2 is no longer supported. If necessary, you can download earlier mono versions.

In addition, I found that there is a. MDB file with the same name under the library file.

 

Deleting the. MDB file does not affect the program. Therefore, you can delete it.

After layer-by-layer deletion, the remaining files add up to more than 8 Mb. The program has no problems at all. Perfect run!

 

When releasing software, use RAR to compress it. The program is more than 3 m. Perfect!

But how do I know .. What libraries does my program use?

The answer is: no. It is too tired to remember which databases are used by the program. I won't remember it. I have a way to be lazy. Create a folder and store the unchanged files first. Mon.exe, mono-2.0.dll, Lib \ mono \. Net version \ mscorlib. dll in the bindirectory. Finally, copy all the library files in Lib \ mono \ GAC under mono. Run the compiled C # program. Now we can start to delete objects in a crazy way. When we encounter objects that cannot be deleted, the rest is the library that our program uses. This method is simple, efficient, and uncomfortable.

 

But there is another problem: Mono's annoying command line. What if a. net library is installed on a computer? Isn't it better to use MS's own. Net? So I wrote a. Net Bootstrap program using C and Windows APIs according to the mono official website. You can select the. NET version based on the settings. If the customer's computer has installed the user-specified version, the Ms. NET is preferred. If it does not exist, the mono boot program is used.

This pilot program uses config. ini as the configuration file.

 

C # _ version = 2.0 //. Net version, which has four values: 2.0, 3.5, 4.0c, and 4.0f

C#_appname1_mybooks.exe // name of the pre-started Application

This Bootstrap program is compiled using vs 2008 in 32-bit XP. Because it is written using Windows APIs, there is no additional library. Therefore, in theory, 32-bit systems can be used, and 64-bit systems have never been used. This pilot program tests the. NET 2.0 project and the. NET 4.0 Project. This program calls the mono-2.0.dll directly. Mono.exe is useless. The following shows my test project and runs monologin.exe directly. I am very satisfied with the results. At the same time, welcome to exchange!

Download project demo

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: info-contact@alibabacloud.com 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.