2010-08-19 25 views
1

我正在使用C#,我希望得到一些在我的項目中引用的dll的版本。我知道我可以簡單地通過假定該文件位於當前文件夾中來獲取它,但是,情況並非總是如此。有沒有更強大的方法來做到這一點?如何獲取項目參考的版本?

回答

5

Getting File Version Information

例如,

AssemblyName[] asmNames = asm.GetReferencedAssemblies(); 
foreach (AssemblyName nm in asmNames) 
{ 
    Console.WriteLine(nm.FullName); 
} 


private bool GetReferenceAssembly(Assembly asm) 
     { 
       try 
       { 
        AssemblyName[] list = asm.GetReferencedAssemblies(); 
        if (list.Length > 0) 
        { 
         AssemblyInformation info = null; 
         _lstReferences = new List(); 
         for (int i = 0; i < list.Length; i++) 
         { 
          info = new AssemblyInformation(); 
          info.Name = list[i].Name; 
          info.Version = list[i].Version.ToString(); 
          info.FullName = list[i].ToString(); 

          this._lstReferences.Add(info); 
         } 
        } 
       } 
       catch (Exception err) 
       { 
        this._errMsg = err.Message; 
        return false; 
       } 

       return true; 
     } 
0

您可以使用下面的代碼來獲得大會女巫的位置包含指定類

System.Reflection.Assembly.GetAssembly(typeof(SpecifiedClass)).Location 
+0

我感興趣的特定的DLL在程序集的參考列表中。 – sbenderli 2010-08-19 15:34:22

+0

因此,您嘗試檢查項目中每個參考的版本或位置? – peter 2010-08-19 15:36:13

+0

是的,如0A0D的例子 – sbenderli 2010-08-19 17:33:12