sbenderli
sbenderli

Reputation: 3794

How to get versions of project references?

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?

Upvotes: 1

Views: 2343

Answers (2)

user195488
user195488

Reputation:

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;
       }

Upvotes: 5

peter
peter

Reputation: 563

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

Upvotes: 0

Related Questions