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?
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.
Open Visual Studio->Tools->Create GUID->Registry Format->New GUID. It will create a new GUID every time you click New GUID.
Initializes a new instance of the Guid structure. public: static Guid NewGuid(); C# Copy.
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.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With