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

How to convert a simple .Net console project a into portable exe with Mono and mkbundle?(如何使用 Mono 和 mkbundle 将简单的 .Net 控制台项目转换为可移植的 exe?)
本文介绍了如何使用 Mono 和 mkbundle 将简单的 .Net 控制台项目转换为可移植的 exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我简单的纯 .Net 2.0 控制台实用程序转换为便携式 exe,我可以将它放在 U 盘上并运行,而不必担心 CLR 和框架库是否安装在特定机器上.

I'd like to convert my simple pure .Net 2.0 console utility into a portable exe which I could just put on an USB stick and run without having to worry whether the CLR and framework libraries are installed on a particular machine or not.

Stackoverflow 已经有 一些关于使用 /mono-project.com/" rel="nofollow noreferrer">Mono 和 Mkbundle 用于从 .Net 项目创建独立的 Windows exe,但我想要的是一个紧凑但有用的 HOWTO.

Stackoverflow already has some information on using Mono and Mkbundle for creating self-contained Windows exes from .Net-projects, but what I would like to have is a compact but useful HOWTO.

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

What are the minimum steps for achieving a portability from a simple C# Visual Studio project?

推荐答案

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

I have found a simple how-to here, however, as I have not tested it myself, I cannot guarantee results. As usual YMMV.

引用原文章(请同时关注原文章的主题):

Quote from the original article (please follow the thread on the original article as well though):

Mkbundle:将 Mono 与您的应用程序捆绑在一起

您有没有想过为什么需要安装 .NET Framework 或 Mono 来运行您的程序?好吧,如果您可以分发您的应用程序而不用唠叨您的客户安装额外的框架,那会更方便,不是吗?所以我们在这里.让我们将基于 .NET 的应用程序与 Mono 捆绑在一起,这样您就不需要安装 Mono 或 .NET 来运行它.

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.

准备环境

首先您需要安装最新的 Mono 和 Cygwin.安装 Mono 非常简单,因此您不会搞砸任何事情.当您开始安装 Cygwin 时,进入完整视图,然后请包含 4 个附加包.它们是:gcc、mingw、mingw-zlib 和 zlib.

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.

现在您需要一个命令提示符.Mono 和 Cygwin 都为桌面上的命令提示符创建快捷方式,但您需要将它们组合成一个.这是为我做的一批.例如,如果您有其他 Mono 版本,您可能需要更改它.

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~1Mono-2.4in' to PATH
PATH=C:PROGRA~1Mono-2.4in;%PATH%

chdir C:cygwinin
bash --login -i

使用 Mono 捆绑应用程序

所以我们现在在命令提示符下,运行这个 Cygwin 模式.请注意,这不再是 DOS 提示符,并且dir"将不再起作用.要列出文件,请使用 linux 命令ls".您现在浏览的文件夹如下所示.Arek 是一个用户名.代码:

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:cygwinhomeArek

使用您的资源管理器浏览到此文件夹.现在您将 2 个文件复制到此文件夹中.第一个是您的应用程序 exe,第二个是您可以在 Mono 文件夹中找到的文件 Mono.dll (2MB).代码:

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 FilesMono-2.4in

由于某些原因,整个过程不适用于长文件名,因此请重命名您的应用程序 exe.它应该符合这个旧的 DOS 8.3 命名.

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.

让我们回到命令提示符.您只需要 1 个命令即可捆绑您的应用程序,这里有一些解释.

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

mkbundle 是 Mono 包中的一个程序 |-o Bundled1.exe 指定如何命名 Mono 捆绑的 exe |Winform1.exe 说明将包含什么,无论如何都会包含 Mono 库 |--deps 是必要的,虽然我不确定它的作用 |-z 会大量压缩输出的exe文件

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

现在您获得了 Bundled1.exe,其中包含您自己的应用程序以及 Mono 本身.您不需要 Mono 或 .NET 来运行它.请注意,它将是 4MB 或更大的大小.那些捆绑的 exe 不是轻量级的.

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.

这篇关于如何使用 Mono 和 mkbundle 将简单的 .Net 控制台项目转换为可移植的 exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)