I am trying to build a console utility that needs to be run in environments that may not have .NET installed. Mono\'s mkbundle seems to be a great solution for this problem,
and i'm using windows 10 and windows10sdk,the compile command is like this:
cl.exe /MT /I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um" /I "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\shared" /I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" /I "C:\Program Files (x86)\Mono\include\mono-2.0" /I "." "temp.c" "temp.o" "C:\Program Files (x86)\Mono\lib\monosgen-2.0.lib" /link /ENTRY:mainCRTStartup kernel32.lib version.lib Ws2_32.lib Mswsock.lib Psapi.lib shell32.lib OleAut32.lib ole32.lib winmm.lib user32.lib libvcruntime.lib advapi32.lib OLDNAMES.lib libucrt.lib /out:tt2.exe
and then do following actions:
copy monosgen-2.0.dll from C:\Program Files (x86)\Mono\bin to your mkbundled application directory.
copy all of .dll files from C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86 to your mkbundled application directory. then run your application which mkbundled .
you will get your wanted result.
also:
and , do not put your bundled application to non-ANSI path , because of the mkbundle do not fully support the non-ANSI path on windows. to resolv this issue: you can edit the temp.c file ,
typed SetEnvironmentVariable("UTF16"); in method body first line : int main(int argc,char* argv[])
then your bundled application can run in any path, but there still some issue : in your c# application which to be mkbundle, you can not use AppDomain.CurrentDomain.BaseDirectory to get the application exist directory. and another issue ,if your application use app.config ,and define some variable in appsettings . after you bundled your application ,it can not read the variable from .config file, the reaseon sames to AppDomain.CurrentDomain.BaseDirectory issue.
that appears to be the mkbundled application in the creation of appdomain have bugs when processing the non-ANSI path.
i work around for this issue ,and reading the mono source code ,but there no solution has been found so far.
after last post from me. I tried a lot of ways.
finally , i found how to resolve this issue.
you must use mkbundle like this:
mkbundle --deps mkbundleTest.exe -o test.exe --keeptemp
the point is the --keeptemp param.
with this param ,mkbundle will save the temp.c file on your current directory.
then copy out this line :
cl.exe /MT /I "C:\Program Files (x86)\Windows Kits\8.1\Include\um" /I "C:\Program Files (x86)\Windows Kits\8.1\Include\shared" /I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" /I "C:\Program Files (x86)\Mono\include\mono-2.0" /I "." "temp.c" "temp.o" "C:\Program Files (x86)\Mono\lib\monosgen-2.0.lib" /link /NODEFAULTLIB /SUBSYSTEM:windows /ENTRY:mainCRTStartup kernel32.lib version.lib Ws2_32.lib Mswsock.lib Psapi.lib shell32.lib OleAut32.lib ole32.lib winmm.lib user32.lib libvcruntime.lib advapi32.lib OLDNAMES.lib libucrt.lib /out:test.exe
remove two params from this line: /NODEFAULTLIB /SUBSYSTEM:windows ,
the final command line like this:
cl.exe /MT /I "C:\Program Files (x86)\Windows Kits\8.1\Include\um" /I "C:\Program Files (x86)\Windows Kits\8.1\Include\shared" /I "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" /I "C:\Program Files (x86)\Mono\include\mono-2.0" /I "." "temp.c" "temp.o" "C:\Program Files (x86)\Mono\lib\monosgen-2.0.lib" /link /ENTRY:mainCRTStartup kernel32.lib version.lib Ws2_32.lib Mswsock.lib Psapi.lib shell32.lib OleAut32.lib ole32.lib winmm.lib user32.lib libvcruntime.lib advapi32.lib OLDNAMES.lib libucrt.lib /out:test.exe
then you will get your bundled application.
and this way working for me.