开发者

How to define working directories for DLL dependencies in Visual Studio / C#

I've got an executeable file, which I run for example from C:. The executable references some DLLs from another directory, let's say C:\MyDLLs. The problem is, that these referenced DLLs 开发者_如何学运维again depend on other DLLs, which are stored in another directory. Can I tell Visual Studio where to look for these missing DLLs? Thanks a lot!


You can reference assemblies outside of your app's assembly loading rules by setting these values in configuration. Here's a sample configuration file from this Microsoft KB article:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="MyAssembly2"  culture="neutral" publicKeyToken="307041694a995978"/>
            <codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

You use the <codeBase> element to tell your app where to look.

You have to make the assembly strong named (use the sn.exe tool) for this to work.

It's also useful to understand how the runtime resolves assembly references and maybe you can take advantage of that instead of going through all the hoops to use <codeBase>.


I've had this issue before and I created a post build script that copies all the needed DLLs into my executable's directory.

Something like: copy "$(ProjectDir)Resources\DLLs\yourDLL.dll" "$(TargetDir)yourDLL.dll"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜