Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between GUID and ID in a .vsct file in Visual Studio extension programming?

e.g. Consider the following code:

<Group guid="guidFirstCommandCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

<Group guid="guidSecondCommandCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

Here, why do we need to define both GUID and ID? id="IDM_VS_MENU_TOOLS" refers to Tools menu in Visual Studio. What is the use of guid="guidSHLMainMenu"?

Also consider the following code:

  <Button guid="guidSecondCommandCmdSet" id="cmdidSecondCommand" priority="2" type="Button">
    <Parent guid="guidSecondCommandCmdSet" id="MyMenuGroup"/>
    <Icon guid="guidImages" id="bmpPic2"/>
    <Strings>
      <ButtonText>XXX Command</ButtonText>
    </Strings>
  </Button>

I understand that the button has the id called "cmdidSecondCommand", but where would the GUID of the button be used? We are already defining the Parent container of the button in the next element.

like image 552
Shrey Baxi Avatar asked Feb 04 '16 12:02

Shrey Baxi


Video Answer


1 Answers

A GUID is as the name implies a globally unique identifier in the form of {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. An ID is a key (or identifier); which is used like a constant allowing to give descriptive names to numeric values.

Since the values behind an ID are not unique over all command sets (or image-strips), the GUID is used to put them into context... a combination of a guid and a numeric value is used to uniquely identify groups, menus, toolbars, buttons, images etc...

In the given example MyMenuGroup and IDM_VS_MENU_TOOLS could potentially have the same mumeric value, but the guids guidSecondCommandCmdSetand guidSHLMainMenu put them into context...

<Group guid="guidSecondCommandCmdSet" id="MyMenuGroup" priority="0x0600">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

You need the GUID and the ID when you want to register Execute- and QueryStatus handlers for controls in your code, set an icon for a button, set elements into relation; for instance adding a group to a toolbar, or menu and so on...

like image 190
Matze Avatar answered Sep 28 '22 14:09

Matze