Run mono .exe with the DLL's in a different folder
Asked Answered
S

1

8

I compiled the test.cs file (which references a third party library) using the dmcs executable for Mac and the following command line program:

dmcs /out:program.exe test.cs /target:exe /reference:/Users/kevin/path/to/bin/Debug/project.dll 

This compiled with no problems (excluding the /reference argument causes issues). This created a program.exe executable in the current directory. When I tried to run it like this:

mono program.exe

I got the following error:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'project, Version=3.4.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

The only way I could figure out to solve this was by copying the project.dll file into the directory containing the program.exe file. Once I copied project.dll into the same directory, the program ran correctly.

Is there an extra argument I can pass to mono to specify DLL's in a different program directory? Or, is there a flag I can pass to dmcs to get it to compile the DLL`s directly into the binary?

Seismography answered 25/12, 2012 at 9:29 Comment(2)
There is e.g. Ilmerge which you can use to link dlls and exe into one file. I do believe there is also a tool from/for mono which does the same.Chicanery
Hi, I am working on Ubuntu 20.04 and using mono for running a *.cs file. This file needs a set of DLLs which I had passed in command: mcs SupervisorTest.cs -r:System.Data.dll -r:CLASSES.DLL and run mono SupervisorTest.exe I have also copied DLL at the same place but it is still failed.Menke
E
3

You can use the probing element in app.config to achieve what you want

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin2\subbin;bin3"/>
      </assemblyBinding>
   </runtime>
</configuration>

Where you set privatePath to whatever directory you want. http://msdn.microsoft.com/en-us/library/823z9h8w(v=vs.80).aspx

However, unless you specify a sub directory, I'd strongly advice against this. If you really do not want to have the assembly in the same directory, consider linking as Uwe Keim suggested or use the GAC.

Linking: http://www.mono-project.com/Linker

GAC: http://www.mono-project.com/Assemblies_and_the_GAC

Extravascular answered 25/12, 2012 at 9:46 Comment(2)
You don't... it's a post build operation so you create a build script using MSBUILD, Make, a shell script or something like it. First you compile then you use the linker and finally mkbundle (if you want)Extravascular
In the above GAC link, TLDR: export MONO_PATH=/path/to/assemblies:/another/path/to/assemblies. Then run mono program.exe again.Hampson

© 2022 - 2024 — McMap. All rights reserved.