I need to access the assembly of my project in C# .NET2.0.
I can see the GUID in the \'Assembly Information\' dialog in under project properties, and at the moment
In case anyone else is looking for an out of the box working example, this is what I ended up using based on the previous answers.
using System.Reflection;
using System.Runtime.InteropServices;
label1.Text = "GUID: " + ((GuidAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute), false)).Value.ToUpper();
Since this has gotten a little bit of attention I decided to include another way of doing it I've been using. This way allows you to use it from a static class:
///
/// public GUID property for use in static class
///
/// Returns the application GUID or "" if unable to get it.
static public string AssemblyGuid
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), false);
if (attributes.Length == 0) { return String.Empty; }
return ((System.Runtime.InteropServices.GuidAttribute)attributes[0]).Value.ToUpper();
}
}