[英]How to get the physical path of the referenced assemblies
我有一個主組件,這個組件引用了一些更多的組件。 我能夠獲得那些引用的匯編名稱。 但是,我無法檢索那些引用程序集的物理路徑。 任何人都可以幫助我嗎?
我使用以下代碼。
string path = Path.GetFullPath(txtFileName.Text);
Assembly a = Assembly.LoadFrom(path);
foreach (AssemblyName an in a.GetReferencedAssemblies()) {
Assembly asm = Assembly.Load(an);
MessageBox.Show(an.FullName.ToString() + "Location : " + asm.CodeBase.ToString());
}
它給了我系統組件“mscorlib”的路徑。 但是當它嘗試檢索用戶創建的程序集時,它會顯示“系統找不到指定的文件”。
也許是這樣的:
string path = System.Reflection.Assembly.GetAssembly(typeof(asm)).Location;
string dir = Path.GetDirectoryName( path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.