Loading dlls from path specified in SetdllDirectory in c#

前端 未结 2 1228
盖世英雄少女心
盖世英雄少女心 2020-12-18 04:47

I am new in dotnet.I have a dotnet dll that loads a c dll by using DllImport. I want to place all the dlls in a folder which is diffrent from the l

2条回答
  •  旧巷少年郎
    2020-12-18 05:20

    I'd suggest adding the directory path to PATH env variable in runtime, using the following code:

    var dllDirectory = @"C:/some/path";
    Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dllDirectory);
    

    That way, the change is only affecting the running process and is discarded when it exits.

提交回复
热议问题