Search code examples
visual-studio-2010deploymentpublishuniqueidentifier

Unique id/code of every deployed application


I believe every deployed product (application) from VS has a unique id or smth like that, that doesn't change over distribution. What I mean is that I publish an app and give it to a company with 100 employees and the product remains with the same unique ID on every single PC it is installed.

I have come across GUID from Assembly Information of the program's project, but I am not sure it is that one. So is there anything like such unique id of the product, and if yes - where can I find it AND how can I access it in the code itself. I.e.: string uniqueID = Something.getProductID() or whatever...


Solution

  • There are two methods to get GUID,

    Fristly, you can get GUID in Assembly Information.

    //Gets the assembly that contains the code that is currently executing.
    Assembly asm = Assembly.GetExecutingAssembly();
    Guid id= asm.GetType().GUID;
    

    Secondly, It is not taken from the Assembly Information.Stored as a real custom attribute.

    var attribute = (GuidAttribute)asm.GetCustomAttributes(typeof(GuidAttribute),true)[0].;
    var id = attribute.Value;
    

    More info you can see

    Assembly.GetCustomAttributes Method (Type, Boolean)

    http://msdn.microsoft.com/en-us/library/88d17d13.aspx

    Assembly.GetExecutingAssembly Method

    http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getexecutingassembly.aspx