in

Bunker Hollow

Matt Williamson's home on the web, welcome.

Matt Williamson's Blog

Personal discoveries of an IT professional.

.NET Get Assembly Information (Title, Version, etc)

| Share

I'm working on a new WPF application and I've started with the basics as usual; a menu bar, file, exit, help, and an about dialog box.  But it's not going quick and easy, I'm surprised at how difficult it is to access the assembly information that you specify for each project and that it isn't all accessible the same way.  Using another excellent CodeProject article as a guide, I've created a static C# AssemblyInfo class to easily access the assembly information for each of your projects.  Simply add this class to each of your projects and correct the namespace.

Download the AssemblyInfo Class

Published Apr 29 2009, 04:35 PM by Matt Williamson
Filed under: , , , ,

Comments

 

Matt Williamson said:

UPDATE - Added FileName and FilePath properties.

April 30, 2009 9:02 AM
 

Alan Jackson said:

Hey Matt, Good Stuff Here.  I was able to use most of this for a Silverlight class which does the same thing for a xap file.  Can't do all the same stuff in SL as it will throw security exceptions trying to get the name of the assembly.  But for an example of how to workaround that, I have included here the code that I am using for getting the AssemblyVersion

Public Shared Function AssemblyVersion() As String

Dim assembly As Assembly

Dim strFullName As String

Dim strFullNameElements() As String

Dim strVersionElements() As String

Dim strReturn As String = String.Empty

assembly = System.Reflection.Assembly.GetExecutingAssembly()

strFullName = assembly.FullName()

strFullNameElements = strFullName.Split(",")

If strFullNameElements.Length > 1 Then

strVersionElements = strFullNameElements(1).Split("=")

If strVersionElements.Length > 1 Then

strReturn = "Build: " & strVersionElements(1)

End If

End If

Return strReturn

End Function

June 4, 2009 6:49 AM
 

Matt Williamson said:

Thanks Alan.  That'll be nice to have when I try my hand at some SilverLight.

PS - If you're the singer/songwriter I'd appreciate it if you'd print this out, sign it, and mail it to me :)

June 4, 2009 9:57 AM
 

orlando said:

Thanks a lot for the code. very useful indeed!!

June 5, 2009 6:57 AM
 

vip said:

It's better to have GetCallingAssembly() instead of GetExecutingAssembly(), cause it raises usability in other classes.

June 18, 2009 7:17 AM
 

Matt Williamson said:

No, that would be a mistake.  If you add this class to all of your projects (let's say a winform and a class library) using GetCallingAssembly() and you then request the FileName of your class library, it will actually return the FileName of the EXE instead of the FileName of your DLL.

June 18, 2009 8:21 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
Powered by Community Server (Non-Commercial Edition), by Telligent Systems