1

I'm having a nightmare. I can't seem to get mkbundle to work on Windows using the current version of Mono (5.0.1.1). It's installed in:

C:\Program Files (x86)\Mono

I've got a very simple console application which uses a .net library, made using Xamarin Studio Community 6.1.2 (build 44). It's very simple, the application calls a function in the library and receives a string in return. It then prints this string out to the console.

The application has been compiled targeting "Mono 5.0.1 (Visual) (C:\Program Files (x86)\Mono)" in Xamarin. I had to disable the use of MSBuild engine to get this working. I can confirm the application works as expected running using mono from the command line.

Now I want to package it up so it's all bundled in one simple executable along with the mono runtime environment, so neither mono or .net is required. It all has to be self-contained. I'd also like to include other resource files that the application will use that aren't DLLs.

So after some searching I found mkbundle which seems to tick all the boxes...

First I followed this: How to make "mkbundle --deps" option working with mono 3.2.3

Then I tried this: https://gist.github.com/tebjan/5581296

Then I tried to follow this as best I could: Can not compile simple C# application with mkbundle

Nothing seems to work D:

I understand that these guides/scripts are likely out of date, but I can't even see a way of updating (massive noob with mono at the moment). As an example, here are two errors I've received when attempting to run mkbundle from cmd:

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

And this an example of me running from mono (although I'm pretty sure I there shouldn't be any difference).

 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

Would someone please be awesome, and give me a more up-to-date guide/walkthrough in how to setup the environment?

Thanks in advance, if I'm missing something obvious please feel free to abuse. Apologies for any ignorance in advance. I've been at this for about 12 hours now and I'm losing my mind!

To clear up any queries regarding my use of Mono on a Windows platform. I'm doing it for two reasons. I'd like to be able to bundle the runtime with the application, as it has to be an application that runs without install (double-click to run and off it goes to finish). I don't think this is possible in current .net (I know .net core is playing with some magic to do with compiling to native but it seems very early days) and I tried C++ but got nauseous.

user3078629
  • 139
  • 1
  • 2
  • 9
  • take a look on my post answer here: https://stackoverflow.com/questions/39905982/on-windows-mkbundle-fails-with-linker-error/41072885#41072885 that may be help you – azraelrabbit Oct 18 '17 at 14:54

1 Answers1

2

It honestly blows my mind that this question sat here for 9 months with no answer (And the same issue still exists too).

So, I recently had the same problem. I checked out the source code here : 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");

So it's looking for a file named "mono" in your SDK bin folder. Well.. Since we are on Windows we don't have extension-less apps right? So this is a bit of a problem. The fix is to head to your SDK bin folder (Which is probably C:\Program Files (x86)\mono\bin\), and make a copy of mono.exe and remove the extension. So it looks like :

enter image description here

Then your mkbundle command will pass this first hurdle. I've also logged a Github issue here if you want to join in about how stupid this is : https://github.com/mono/mono/issues/7731

Now once you get past this, you are going to run into the next issue which is that fetching additional runtimes so you can actually compile for Linux is also going to fail. I recommend just following this guide : https://dotnetcoretutorials.com/2018/03/22/bundling-mono-with-a-net-executable-using-mkbundle-on-windows/ which should get you all the way through.

MindingData
  • 11,924
  • 6
  • 49
  • 68