Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically get the GUID of an application in .NET 2.0

I need to access the assembly of my project in C# .NET 2.0.

I can see the GUID in the 'Assembly Information' dialog in under project properties, and at the moment I have just copied it to a const in the code. The GUID will never change, so this is not that bad of a solution, but it would be nice to access it directly. Is there a way to do this?

like image 557
Nathan Avatar asked Feb 02 '09 05:02

Nathan


People also ask

How do I programmatically get the GUID?

This will get the GUID for the current assembly: Assembly asm = Assembly. GetExecutingAssembly(); object[] attribs = asm. GetCustomAttributes(typeof(GuidAttribute), true); var guidAttr = (GuidAttribute) attribs[0]; Console.

How to get GUID in c#?

Open Visual Studio->Tools->Create GUID->Registry Format->New GUID. It will create a new GUID every time you click New GUID.

What is GUID NewGuid () in C#?

Initializes a new instance of the Guid structure. public: static Guid NewGuid(); C# Copy.

What is .NET GUID?

A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.


1 Answers

Try the following code. The value you are looking for is stored on a GuidAttribute instance attached to the Assembly

using System.Runtime.InteropServices;  static void Main(string[] args) {     var assembly = typeof(Program).Assembly;     var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute),true)[0];     var id = attribute.Value;     Console.WriteLine(id); } 
like image 175
JaredPar Avatar answered Sep 21 '22 14:09

JaredPar