简体   繁体   English

使用DLL在另一个文件夹中运行mono .exe

[英]Run mono .exe with the DLL's in a different folder

I compiled the test.cs file (which references a third party library) using the dmcs executable for Mac and the following command line program: 我使用Mac的dmcs可执行文件和以下命令行程序编译了test.cs文件(引用第三方库):

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). 编译没有问题(排除/ reference参数导致问题)。 This created a program.exe executable in the current directory. 这在当前目录中创建了一个program.exe可执行文件。 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. 我能解决这个问题的唯一方法是将project.dll文件复制到包含program.exe文件的目录中。 Once I copied project.dll into the same directory, the program ran correctly. project.dll复制到同一目录后,程序运行正常。

Is there an extra argument I can pass to mono to specify DLL's in a different program directory? 是否有一个额外的参数我可以传递给mono以在另一个程序目录中指定DLL? Or, is there a flag I can pass to dmcs to get it to compile the DLL`s directly into the binary? 或者,是否有一个标志我可以传递给dmcs ,以便将DLL直接编译成二进制文件?

You can use the probing element in app.config to achieve what you want 您可以使用app.config中的探测元素来实现您想要的效果

<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. 将privatePath设置为您想要的任何目录的位置。 http://msdn.microsoft.com/en-us/library/823z9h8w(v=vs.80).aspx 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. 如果您确实不希望将程序集放在同一目录中,请考虑使用Uwe Keim建议的链接或使用GAC。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM