I am using C# and I wish to get the versions of some of the dll's that are in the references of my projects. I know that I can get it simply by assuming that the file is in the current folder, however, this may not always be the case. Is there a more robust way of doing this?
A:
You can use the following code to obtain the location of the assembly witch contains the specified class
System.Reflection.Assembly.GetAssembly(typeof(SpecifiedClass)).Location
peter
2010-08-19 15:32:11
I am interested in the specific dll's within the references list of the assembly.
sbenderli
2010-08-19 15:34:22
So you try to check the version or location for each reference in your project?
peter
2010-08-19 15:36:13
Yes, as in 0A0D's example
sbenderli
2010-08-19 17:33:12
+3
A:
Getting File Version Information
For example,
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;
}
0A0D
2010-08-19 15:33:57