How do I get version resources from the executing assembly?

F

Frank T. Clark

I am having trouble trying to retrieve the version resources of the
executing assembly at runtime. I want to retrieve AssemblyTitle,
AssemblyDescription, AssemblyCompany, AssemblyProduct, and
AssemblyCopyright.I assume it has something to do with GetExecutingAssembly.
What am I missing? A line or two of sample code is greatly appreciated.
Thank you.
 
S

Stefan

Hi Frank
use
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo oFileVersionInfo =
FileVersionInfo.GetVersionInfo(oAssembly.Location);
oFileVersionInfo.FileMajorPart, oFileVersionInfo.FileMinorPart
 
F

Frank T. Clark

Thanks. As I have often said. The answer is simple, once you know the
answer.
 
M

Mattias Sjögren

System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

From there on, I'd use oAssembly.GetName().Version and
oAssembly.GetCustomAttributes() instead to retrieve the information.



Mattias
 
F

Frank T. Clark

A cross-reference for anyone who finds it useful.

// FileVersionInfo.Comments = AssemblyDescription

// FileVersionInfo.CompanyName = AssemblyCompany

// FileVersionInfo.FileDescription = AssemblyTitle

// FileVersionInfo.FileVersion = AssemblyFileVersion

// FileVersionInfo.LegalCopyright = AssemblyCopyright

// FileVersionInfo.LegalTrademarks = AssemblyTrademark

// FileVersionInfo.ProductName = AssemblyProduct

// FileVersionInfo.ProductVersion = AssemblyInformationalVersion
 
F

Frank T. Clark

I am sorry, but I do not find sufficient information in your answer to
implement it.

oAssembly.GetCustomAttributes (?).?
 
M

Mattias Sjögren

Frank,
I am sorry, but I do not find sufficient information in your answer to
implement it.

oAssembly.GetCustomAttributes (?).?

If you for example are looking for the AssemblyTitleAttribute:

object[] attrs =
oAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute));
if ( atts.Length > 0 ) {
AssemblyTitleAttribute ata = atts[0] as AssemblyTitleAttribute;
...
}



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top