开发者

Assembly searchPath via %PATH% environment

开发者 https://www.devze.com 2023-02-23 05:37 出处:网络
I am developing a project 开发者_运维问答and want to seperate the shared assemblies form project folder

I am developing a project 开发者_运维问答and want to seperate the shared assemblies form project folder

+ Program Files
    + My Company

       +Commons
          * Assembly1.dll
          * Assembly2.dll
          * Assembly3.dll
          * Assembly4.dll

       +Project1
          * MyProject1.exe
          * MyProject1.exe.config

       +Project2
          * MyProject2.exe
          * MyProject2.exe.config

trying to make projects load assemblies from "Commons" folder so i change the system %PATH% environment to search for DLLs.

%PATH% = c:\Program files\My Company\Commons;%PATH%

but they dont look up the Path environment (Monitoring with ProcessMonitor) Can anybody show me the way how to define search path for assemblies from %PATH% environment.


string path = System.Environment.GetEnvironmentVariable("Path");
var folders = path.Split(';');
foreach (var folder in folders)
{
    foreach (var file in Directory.GetFiles(folder, "*.*"))
    {
        // found files
    }
}

Do the search in theAppDomain.AssemblyResolve event to find the dlls when your application is starting. More information about the event here: http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx


I don't believe dotNET relies on path environment variable when binding assemblies.

See http://ondotnet.com/pub/a/dotnet/2003/03/17/bindingpolicy.html for a dotNET binding policy.

Especially, you might find the element useful here: http://msdn.microsoft.com/en-us/library/efs781xb%28v=VS.100%29.aspx

0

精彩评论

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