【问题标题】:Difficulty getting mkbundle to work in Windows难以让 mkbundle 在 Windows 中工作
【发布时间】:2018-03-22 07:02:17
【问题描述】:

我做噩梦了。我似乎无法让 mkbundle 使用当前版本的 Mono (5.0.1.1)Windows 上工作。它安装在:

C:\Program Files (x86)\Mono

我有一个非常简单的控制台应用程序,它使用 .net 库,使用 Xamarin Studio Community 6.1.2(内部版本 44) 制作。很简单,应用程序调用库中的一个函数并接收一个字符串作为返回。然后它将这个字符串打印到控制台。

该应用程序已针对 Xamarin 中的“Mono 5.0.1 (Visual) (C:\Program Files (x86)\Mono)”进行编译。我必须禁用 MSBuild 引擎才能使其正常工作。我可以从命令行使用 mono 确认应用程序按预期运行。

现在我想将它打包,以便与单声道运行时环境一起捆绑在一个简单的可执行文件中,因此不需要单声道或 .net。这一切都必须自给自足。我还想包含应用程序将使用的不是 DLL 的其他资源文件。

所以经过一番搜索,我发现 mkbundle 似乎勾选了所有框...

首先我遵循了这个: How to make "mkbundle --deps" option working with mono 3.2.3

然后我尝试了这个: https://gist.github.com/tebjan/5581296

然后我尽我所能地遵循这个: Can not compile simple C# application with mkbundle

似乎没有任何效果 D:

我知道这些指南/脚本可能已经过时了,但我什至看不到更新的方法(目前是单声道的大量新手)。例如,以下是我在尝试从 cmd 运行 mkbundle 时收到的两个错误:

C:\Users\asdf\Documents\Projects\Test\Test\bin\Debug>mkbundle Test.exe --simple -o super.exe
ERROR: The SDK location does not contain a C:\Program Files (x86)\Mono/bin/mono runtime

Unhandled Exception:
System.Exception: Exception of type 'System.Exception' was thrown.
  at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.Main (System.String[] args) [0x00bd4] in <140d0f6d64494c449b7d56649165e7e4>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Exception of type 'System.Exception' was thrown.
  at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.Main (System.String[] args) [0x00bd4] in <140d0f6d64494c449b7d56649165e7e4>:0

C:\Users\asdf\Documents\Projects\Test\Test\bin\Debug>mkbundle --sdk "C:\Program Files (x86)\Mono\bin" Test.exe --deps -o super.exe
ERROR: The SDK location does not contain a C:\Program Files (x86)\Mono\bin/bin/mono runtime

Unhandled Exception:
System.Exception: Exception of type 'System.Exception' was thrown.
  at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.Main (System.String[] args) [0x00b88] in <140d0f6d64494c449b7d56649165e7e4>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Exception of type 'System.Exception' was thrown.
  at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
  at MakeBundle.Main (System.String[] args) [0x00b88] in <140d0f6d64494c449b7d56649165e7e4>:0

这是我从单声道运行的一个例子(尽管我很确定我不应该有任何区别)。

 asdf@DIGGLER /cygdrive/c/Users/asdf/Documents/Projects/ConsoleAppAOTDllTest/Co                                                                                                                                                                                               nsoleAppAOTDllTest/bin/Debug
    $ mkbundle --simple testlib.exe -o super.exe
    ERROR: The SDK location does not contain a C:\Program Files (x86)\Mono/bin/mono runtime

    Unhandled Exception:
    System.Exception: Exception of type 'System.Exception' was thrown.
      at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
      at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
      at MakeBundle.Main (System.String[] args) [0x00bd4] in <140d0f6d64494c449b7d56649165e7e4>:0
    [ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Exception of type 'System.Exception' was thrown.
      at MakeBundle.Error (System.String msg, System.Object[] args) [0x00016] in <140d0f6d64494c449b7d56649165e7e4>:0
      at MakeBundle.VerifySdk (System.String path) [0x00052] in <140d0f6d64494c449b7d56649165e7e4>:0
      at MakeBundle.Main (System.String[] args) [0x00bd4] in <140d0f6d64494c449b7d56649165e7e4>:0

有没有人可以给我一个关于如何设置环境的最新指南/演练?

提前致谢,如果我遗漏了一些明显的东西,请随意滥用。 提前为任何无知道歉。我已经在这玩了大约 12 个小时了,我快疯了!

清除有关我在 Windows 平台上使用 Mono 的任何疑问。我这样做有两个原因。我希望能够将运行时与应用程序捆绑在一起,因为它必须是无需安装即可运行的应用程序(双击运行并关闭它即可完成)。我认为这在当前的 .net 中是不可能的(我知道 .net 核心正在玩一些与编译到本机有关的魔法,但似乎还很早),我尝试了 C++,但感到恶心。

【问题讨论】:

标签: c# .net mono monodevelop


【解决方案1】:

老实说,这个问题在这里坐了 9 个月没有答案(同样的问题仍然存在),这让我大吃一惊。

所以,我最近遇到了同样的问题。我在这里查看了源代码:https://github.com/mono/mono/blob/master/mcs/tools/mkbundle/mkbundle.cs#L536

runtime = Path.Combine (sdk_path, "bin", "mono");
if (!File.Exists (runtime))
    Error ($"The SDK location does not contain a {path}/bin/mono runtime");

所以它在您的 SDK bin 文件夹中寻找一个名为“mono”的文件。嗯.. 由于我们在 Windows 上,我们没有无扩展的应用程序,对吧?所以这有点问题。修复方法是转到您的 SDK bin 文件夹(可能是 C:\Program Files (x86)\mono\bin\),然后复制 mono.exe 并删除扩展名。所以它看起来像:

然后您的 mkbundle 命令将通过这第一个障碍。如果您想了解这有多愚蠢,我还在这里记录了一个 Github 问题:https://github.com/mono/mono/issues/7731

现在,一旦您克服了这一点,您将遇到下一个问题,即获取额外的运行时以便您可以实际为 Linux 编译也会失败。我建议您遵循本指南:https://dotnetcoretutorials.com/2018/03/22/bundling-mono-with-a-net-executable-using-mkbundle-on-windows/,它应该可以帮助您完成所有工作。

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 2011-07-28
    • 2013-04-28
    • 2017-08-18
    • 2018-02-26
    相关资源
    最近更新 更多