c# - 如何使用 Mono 和 mkbundle 将一个简单的 .Net 控制台项目转换为可移植的 exe?

标签 c# .net mono portability mkbundle

我想将我简单的纯 .Net 2.0 控制台实用程序转换成一个可移植的 exe,我可以将它放在 USB 内存棒上运行,而不必担心 CLR 和框架库是否安装在特定机器上.

Stackoverflow 已有 some information关于使用 MonoMkbundle用于从 .Net 项目创建独立的 Windows exe,但我想要的是一个紧凑但有用的 HOWTO。

从简单的 C# Visual Studio 项目实现可移植性的最少步骤是什么?

最佳答案

我找到了一个简单的方法 here但是,由于我没有亲自测试过,我不能保证结果。像往常一样 YMMV。

引自原文(请继续关注原文中的主题):

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.

Code:

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. Code:

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. Code:

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

Code:

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.

关于c# - 如何使用 Mono 和 mkbundle 将一个简单的 .Net 控制台项目转换为可移植的 exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1321207/

相关文章:

c# - 未定义或导入预定义类型“System.ValueTuple´2”

c# - isprefix 是否比在 C# 中比较两个字符串更昂贵?

c# - 在 windows 7 启动时启动程序(自动启动)

.net - Chrome SSL 自签名证书问题

c# - 将位置字符串更改为 const 会破坏我的记录器类

windows-7 - GetThreadContext 导致嵌入式单声道崩溃失败 (Windows 7)

c# - 为什么 C# 数组对枚举使用引用类型,而 List<T> 使用可变结构?

c# - 静态媒体元素

c# - 为什么 !DumpHeap -stat 中的对象总和与 !EEHeap -gc 不匹配?

c# - 在 Mac 上部署没有框架的 Mono 应用程序