CSharp examples for System.Reflection:Assembly
Build Private Bin Path
// This program is free software; you can redistribute it and/or using System.Diagnostics; using System.Reflection; using System.IO;// w w w. j a v a 2s.com using System.Collections; using System; public class Main{ private static void BuildPrivateBinPath (Assembly assembly, string referencedAssembly) { DirectoryInfo baseDir = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); ArrayList possibleDlls = new ArrayList(); FileInfo rootMatch = new FileInfo(Path.Combine(baseDir.FullName, referencedAssembly + ".dll")); if (rootMatch.Exists) { possibleDlls.Add( rootMatch); } // add some other cantidates DirectorySearch(possibleDlls, baseDir, referencedAssembly); FileInfo match = null; foreach (FileInfo possibleDll in possibleDlls) { if (IsMatch(Path.GetDirectoryName(assembly.Location), Path.GetDirectoryName(possibleDll.FullName))) { match = possibleDll; break; } } if (match == null) { throw new Exception("Unable to find correct version of referenced assembly."); } AppDomain.CurrentDomain.AppendPrivatePath(Path.GetDirectoryName(match.FullName)); } }