Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 为服务器资源管理器数据连接中的表节点创建visual studio扩展_Visual Studio_Visual Studio 2017_Visual Studio Extensions - Fatal编程技术网

Visual studio 为服务器资源管理器数据连接中的表节点创建visual studio扩展

Visual studio 为服务器资源管理器数据连接中的表节点创建visual studio扩展,visual-studio,visual-studio-2017,visual-studio-extensions,Visual Studio,Visual Studio 2017,Visual Studio Extensions,我想在服务器资源管理器中列出的sql server数据库中的每个表的每个节点的上下文菜单中添加一个自定义命令 我已经完成了一个基本教程,并在“工具”菜单栏中添加了一个命令以及一个自定义顶级菜单 我还看到了教程,它与我想要做的非常接近,但它特定于sharepoint连接节点,并使用sharepoint特定的IExplorerNodeTypeExtension接口。我很难找到任何与数据连接节点相关的文档。有人能提供我应该使用哪些接口的相关文档或信息吗?通过Jack Zhai的一些提示和其他一些we

我想在服务器资源管理器中列出的sql server数据库中的每个表的每个节点的上下文菜单中添加一个自定义命令

我已经完成了一个基本教程,并在“工具”菜单栏中添加了一个命令以及一个自定义顶级菜单


我还看到了教程,它与我想要做的非常接近,但它特定于sharepoint连接节点,并使用sharepoint特定的IExplorerNodeTypeExtension接口。我很难找到任何与数据连接节点相关的文档。有人能提供我应该使用哪些接口的相关文档或信息吗?

通过Jack Zhai的一些提示和其他一些web资源,我能够找到相关信息

首先,我在Computer\HKEY\u CURRENT\u USER\SOFTWARE\Microsoft\VisualStudio\General中将EnableVSIPLogging设置为1,从而启用了VSIPLogging

然后,我可以通过按住CTRL+SHIFT并右键单击来确定VisualStudio中任何菜单项或树节点的GUID和ID

由此,我能够确定服务器资源管理器中的顶级节点的Guid为{74D21310-2AEE-11D1-8BFB-00A0C90F26F7},命令id为1283

服务器资源管理器中的对象节点(如表、存储过程等)的Guid为{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2},命令id为33280(0x8200)

服务器资源管理器中的对象节点父节点(如静态“表”、“存储过程”、对对象节点进行分类的节点)的guid为{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2},命令id为33024(0x8100)

因此,有了这些guid,我现在可以将命令附加到我想要的地方

我需要一个特定于单个表的命令,以及一个特定于数据库中所有表的命令,因此我将使用命令id为0x8200的d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2和命令id为0x8100的Guid d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2

接下来,我需要在VSIX项目的vsct文件中定义这些值,以便将它们添加到“符号”部分:

我将2个命令项添加到我的项目中,然后我需要更改组的父项,以便它们显示在服务器资源管理器的正确区域中:

现在,database命令确实为所有静态对象节点显示,尽管我希望它仅显示在“Tables”节点上,table命令为所有对象节点及其子节点显示,尽管我希望它仅为表节点本身显示。我认为需要以某种方式在代码中解决这个问题,动态地确定命令菜单项的可见性,但我必须单独计算这个问题

以下是整个vsct:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!--  This is the file that defines the actual layout and type of the commands.
        It is divided in different sections (e.g. command definition, command
        placement, ...), with each defining a specific set of properties.
        See the comment before each section for more details about how to
        use it. -->

  <!--  The VSCT compiler (the tool that translates this file into the binary
        format that VisualStudio will consume) has the ability to run a preprocessor
        on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
        it is possible to define includes and macros with the same syntax used
        in C++ files. Using this ability of the compiler here, we include some files
        defining some of the constants that we will use inside the file. -->

  <!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
  <Extern href="stdidcmd.h" />

  <!--This header contains the command ids for the menus provided by the shell. -->
  <Extern href="vsshlids.h" />

  <!--The Commands section is where commands, menus, and menu groups are defined.
      This section uses a Guid to identify the package that provides the command defined inside it. -->
  <Commands package="guidCRUDSPCommandsPackage">
    <!-- Inside this section we have different sub-sections: one for the menus, another
    for the menu groups, one for the buttons (the actual commands), one for the combos
    and the last one for the bitmaps used. Each element is identified by a command id that
    is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
    called "command set" and is used to group different command inside a logically related
    group; your package should define its own command set in order to avoid collisions
    with command ids defined by other packages. -->

    <!-- In this section you can define new menu groups. A menu group is a container for
         other menus or buttons (commands); from a visual point of view you can see the
         group as the part of a menu contained between two lines. The parent of a group
         must be a menu. -->
    <Groups>

      <!-- Table scope -->
      <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" priority="0x0600">
        <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />-->
        <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_OBJECT_NODE" />
      </Group>

      <!-- Database scope -->
      <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" priority="0x0600">
        <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />-->
        <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_STATIC_NODE" />
      </Group>

    </Groups>

    <!--Buttons section. -->
    <!--This section defines the elements the user can interact with, like a menu command or a button
        or combo box in a toolbar. -->
    <Buttons>
      <!--To define a menu group you have to specify its ID, the parent menu and its display priority.
          The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
          the CommandFlag node.
          You can add more than one CommandFlag node e.g.:
              <CommandFlag>DefaultInvisible</CommandFlag>
              <CommandFlag>DynamicVisibility</CommandFlag>
          If you do not want an image next to your command, remove the Icon node /> -->

      <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdTable" priority="0x0100" type="Button">
        <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Command for Table</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdDatabase" priority="0x0100" type="Button">
        <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" />
        <Icon guid="guidImages1" id="bmpPic1" />
        <Strings>
          <ButtonText>Command for Database</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <!--  The bitmap id is defined in a way that is a little bit different from the others:
            the declaration starts with a guid for the bitmap strip, then there is the resource id of the
            bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
            inside a button definition. An important aspect of this declaration is that the element id
            must be the actual index (1-based) of the bitmap inside the bitmap strip. -->


      <Bitmap guid="guidImages" href="Resources\CmdTable.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
      <Bitmap guid="guidImages1" href="Resources\CmdDatabase.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
    </Bitmaps>
  </Commands>

  <Symbols>
    <!-- {d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2} is the object node in the server explorer -->
    <GuidSymbol name="guidServerExplorerObjectNode" value="{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2}">
      <!--server explorer - table-->
      <IDSymbol name="IDMX_DV_OBJECT_NODE" value="0x8200" />
      <IDSymbol name="IDMX_DV_STATIC_NODE" value="0x8100" />
    </GuidSymbol>

    <!-- {74D21310-2AEE-11D1-8BFB-00A0C90F26F7} is the server explorer -->
    <GuidSymbol name="guidServerExplorer" value="{74D21310-2AEE-11D1-8BFB-00A0C90F26F7}">
      <!--server explorer - table-->
      <IDSymbol name="IDMX_DV_SERVER_NODE" value="0x503" />
    </GuidSymbol>

    <!-- This is the package guid. -->
    <GuidSymbol name="guidCRUDSPCommandsPackage" value="{a71670bc-ef23-40a3-b8a0-ed872b79476c}" />

    <!-- Constants-->
    <GuidSymbol value="{946311de-35f2-4379-84e2-91867976faf8}" name="guidCRUDSPCommandsPackageCmdSet1">
      <IDSymbol value="256" name="cmdidCmdTable" />
      <IDSymbol value="257" name="cmdidCmdDatabase" />
      <IDSymbol value="258" name="TableMenuGroup" />
      <IDSymbol value="259" name="DatabaseMenuGroup" />
    </GuidSymbol>

    <GuidSymbol value="{679ecb35-41d9-4021-933b-ec6b25afc100}" name="guidImages">
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>

    <GuidSymbol value="{9392ca3d-3400-4b7a-a691-7108032249cd}" name="guidImages1">
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

表格命令
数据库命令

通过杰克·翟和其他一些网络资源的提示,我能够找到信息

首先,我在Computer\HKEY\u CURRENT\u USER\SOFTWARE\Microsoft\VisualStudio\General中将EnableVSIPLogging设置为1,从而启用了VSIPLogging

然后,我可以通过按住CTRL+SHIFT并右键单击来确定VisualStudio中任何菜单项或树节点的GUID和ID

由此,我能够确定服务器资源管理器中的顶级节点的Guid为{74D21310-2AEE-11D1-8BFB-00A0C90F26F7},命令id为1283

服务器资源管理器中的对象节点(如表、存储过程等)的Guid为{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2},命令id为33280(0x8200)

服务器资源管理器中的对象节点父节点(如静态“表”、“存储过程”、对对象节点进行分类的节点)的guid为{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2},命令id为33024(0x8100)

因此,有了这些guid,我现在可以将命令附加到我想要的地方

我需要一个特定于单个表的命令,以及一个特定于数据库中所有表的命令,因此我将使用命令id为0x8200的d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2和命令id为0x8100的Guid d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2

接下来,我需要在VSIX项目的vsct文件中定义这些值,以便将它们添加到“符号”部分:

我将2个命令项添加到我的项目中,然后我需要更改组的父项,以便它们显示在服务器资源管理器的正确区域中:

现在,database命令确实为所有静态对象节点显示,尽管我希望它仅显示在“Tables”节点上,table命令为所有对象节点及其子节点显示,尽管我希望它仅为表节点本身显示。我认为需要以某种方式在代码中解决这个问题,动态地确定命令菜单项的可见性,但我必须单独计算这个问题

以下是整个vsct:

<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!--  This is the file that defines the actual layout and type of the commands.
        It is divided in different sections (e.g. command definition, command
        placement, ...), with each defining a specific set of properties.
        See the comment before each section for more details about how to
        use it. -->

  <!--  The VSCT compiler (the tool that translates this file into the binary
        format that VisualStudio will consume) has the ability to run a preprocessor
        on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
        it is possible to define includes and macros with the same syntax used
        in C++ files. Using this ability of the compiler here, we include some files
        defining some of the constants that we will use inside the file. -->

  <!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
  <Extern href="stdidcmd.h" />

  <!--This header contains the command ids for the menus provided by the shell. -->
  <Extern href="vsshlids.h" />

  <!--The Commands section is where commands, menus, and menu groups are defined.
      This section uses a Guid to identify the package that provides the command defined inside it. -->
  <Commands package="guidCRUDSPCommandsPackage">
    <!-- Inside this section we have different sub-sections: one for the menus, another
    for the menu groups, one for the buttons (the actual commands), one for the combos
    and the last one for the bitmaps used. Each element is identified by a command id that
    is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
    called "command set" and is used to group different command inside a logically related
    group; your package should define its own command set in order to avoid collisions
    with command ids defined by other packages. -->

    <!-- In this section you can define new menu groups. A menu group is a container for
         other menus or buttons (commands); from a visual point of view you can see the
         group as the part of a menu contained between two lines. The parent of a group
         must be a menu. -->
    <Groups>

      <!-- Table scope -->
      <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" priority="0x0600">
        <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />-->
        <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_OBJECT_NODE" />
      </Group>

      <!-- Database scope -->
      <Group guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" priority="0x0600">
        <!--<Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS" />-->
        <Parent guid="guidServerExplorerObjectNode" id="IDMX_DV_STATIC_NODE" />
      </Group>

    </Groups>

    <!--Buttons section. -->
    <!--This section defines the elements the user can interact with, like a menu command or a button
        or combo box in a toolbar. -->
    <Buttons>
      <!--To define a menu group you have to specify its ID, the parent menu and its display priority.
          The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
          the CommandFlag node.
          You can add more than one CommandFlag node e.g.:
              <CommandFlag>DefaultInvisible</CommandFlag>
              <CommandFlag>DynamicVisibility</CommandFlag>
          If you do not want an image next to your command, remove the Icon node /> -->

      <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdTable" priority="0x0100" type="Button">
        <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="TableMenuGroup" />
        <Icon guid="guidImages" id="bmpPic1" />
        <Strings>
          <ButtonText>Command for Table</ButtonText>
        </Strings>
      </Button>

      <Button guid="guidCRUDSPCommandsPackageCmdSet1" id="cmdidCmdDatabase" priority="0x0100" type="Button">
        <Parent guid="guidCRUDSPCommandsPackageCmdSet1" id="DatabaseMenuGroup" />
        <Icon guid="guidImages1" id="bmpPic1" />
        <Strings>
          <ButtonText>Command for Database</ButtonText>
        </Strings>
      </Button>
    </Buttons>

    <!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
    <Bitmaps>
      <!--  The bitmap id is defined in a way that is a little bit different from the others:
            the declaration starts with a guid for the bitmap strip, then there is the resource id of the
            bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
            inside a button definition. An important aspect of this declaration is that the element id
            must be the actual index (1-based) of the bitmap inside the bitmap strip. -->


      <Bitmap guid="guidImages" href="Resources\CmdTable.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
      <Bitmap guid="guidImages1" href="Resources\CmdDatabase.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
    </Bitmaps>
  </Commands>

  <Symbols>
    <!-- {d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2} is the object node in the server explorer -->
    <GuidSymbol name="guidServerExplorerObjectNode" value="{d4f02a6a-c5ae-4bf2-938d-f1625bdca0e2}">
      <!--server explorer - table-->
      <IDSymbol name="IDMX_DV_OBJECT_NODE" value="0x8200" />
      <IDSymbol name="IDMX_DV_STATIC_NODE" value="0x8100" />
    </GuidSymbol>

    <!-- {74D21310-2AEE-11D1-8BFB-00A0C90F26F7} is the server explorer -->
    <GuidSymbol name="guidServerExplorer" value="{74D21310-2AEE-11D1-8BFB-00A0C90F26F7}">
      <!--server explorer - table-->
      <IDSymbol name="IDMX_DV_SERVER_NODE" value="0x503" />
    </GuidSymbol>

    <!-- This is the package guid. -->
    <GuidSymbol name="guidCRUDSPCommandsPackage" value="{a71670bc-ef23-40a3-b8a0-ed872b79476c}" />

    <!-- Constants-->
    <GuidSymbol value="{946311de-35f2-4379-84e2-91867976faf8}" name="guidCRUDSPCommandsPackageCmdSet1">
      <IDSymbol value="256" name="cmdidCmdTable" />
      <IDSymbol value="257" name="cmdidCmdDatabase" />
      <IDSymbol value="258" name="TableMenuGroup" />
      <IDSymbol value="259" name="DatabaseMenuGroup" />
    </GuidSymbol>

    <GuidSymbol value="{679ecb35-41d9-4021-933b-ec6b25afc100}" name="guidImages">
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>

    <GuidSymbol value="{9392ca3d-3400-4b7a-a691-7108032249cd}" name="guidImages1">
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      <IDSymbol name="bmpPicSearch" value="3" />
      <IDSymbol name="bmpPicX" value="4" />
      <IDSymbol name="bmpPicArrows" value="5" />
      <IDSymbol name="bmpPicStrikethrough" value="6" />
    </GuidSymbol>
  </Symbols>
</CommandTable>

表格命令
数据库命令