Hi,
Hello,
I want to create a very simple control which displays the assembly name
and version of the DLL where the control is inserted.
Could somebody tell me how can I access the name and version from my
control class?
Thanks,
Miguel
Using Assembly and FileVersionInfo, you can get information about the
assembly attributes:
// First get the Assembly
Type tyType = typeof( MyControl );
Assembly oAssembly = tyType.Assembly;
FileVersionInfo oFileVersionInfo
= FileVersionInfo.GetVersionInfo( oAssembly.Location );
// Name entered in the "Product Name" attribute
string strName = oFileVersionInfo.ProductName;
// Assembly description
string strDescription = oFileVersionInfo.Comments;
// Copyright and Trademark
string strCopyright = oFileVersionInfo.LegalCopyright;
string strTrademark = oFileVersionInfo.LegalTrademarks;
// Company name
string strCompanyName = oFileVersionInfo.CompanyName;
Versions are tricky, because you must distinguish between File Version
and Product Version.
The File Version is the attribute set with
[assembly: AssemblyVersion("1.7.1.*")]
Usually, you want the File Version. You can build the version by using
oFileVersionInfo.FileMajorPart
oFileVersionInfo.FileMinorPart
oFileVersionInfo.FileBuildPart
oFileVersionInfo.FilePrivatePart
The Product Version is set with
[assembly: AssemblyInformationalVersion("1.7.1.12")]
You can get it with
string strProductVersion = oFileVersionInfo.ProductVersion;
HTH,
Laurent