/// <summary> /// 指定したディレクトリを起点とし、環境変数のPATHをプロセス内限定で変更することで /// アンマネージライブラリの参照パスを追加します。 /// </summary> /// <param name="path">指定したディレクトリからの相対パス。親ディレクトリ側を指さないことが推奨されます。</param> /// <param name="modifyMode">起点となるディレクトリの種類</param> public static void AddEnvironmentPath(string path, PathModifyMode modifyMode) { string baseDir = (modifyMode == PathModifyMode.RelativeToEntryAssembly) ? System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : (modifyMode == PathModifyMode.RelativeToExecutingAssembly) ? System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) : Environment.CurrentDirectory; string absDir = System.IO.Path.Combine(baseDir, path); if (!Directory.Exists(absDir)) throw new DirectoryNotFoundException( $"Directory to search was not found, this program expects the directory {absDir} to exists" ); AddEnvironmentPath(absDir); }