사용자 도구

사이트 도구


kb:vspackage

VSPackage

Visual Studio 기능 확장하기.

VS2013을 쓰게 되었는데, 매크로를 더 이상 지원하지 않기 때문에, VSPackage를 통해 기존의 매크로를 변환하기로 했다.

기본적인 사항

필요한 것들

시작하기

  • 신규 프로젝트 생성 → 다른 언어 → Visual C# or Visual Basic → 확장성 → Visual Studio Package

Menu Command 확장

XML 형식의 vsct 파일을 이용해 메뉴 UI를 구성하고, 실제 소스에서 해당 메뉴에 대한 핸들러를 구성하게 된다.

SeriousMacro라는 Menu Command 패키지를 만들었다고 하자.

SeriousMacro.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">
  ......
 
  <Commands package="guidSeriousMacroPkg">
    <Groups>
      <Group guid="guidSeriousMacroCmdSet" id="MainMenuGroup" priority="0x0000">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
      </Group>
      <Group guid="guidSeriousMacroCmdSet" id="SubMenuGroup0" priority="0x0000">
        <Parent guid="guidSeriousMacroCmdSet" id="SubMenu"/>
      </Group>
      <Group guid="guidSeriousMacroCmdSet" id="SubMenuGroup1" priority="0x0000">
        <Parent guid="guidSeriousMacroCmdSet" id="SubMenu"/>
      </Group>
    </Groups>
    <Menus>
      <Menu guid="guidSeriousMacroCmdSet" id="SubMenu" priority="0x0100" type="Menu">
        <Parent guid="guidSeriousMacroCmdSet" id="MainMenuGroup"/>
        <Strings>
          <ButtonText>Serious Macro</ButtonText>
          <CommandName>Serious &amp;Macro</CommandName>
        </Strings>
      </Menu>
    </Menus>
    <Buttons>
      <Button guid="guidSeriousMacroCmdSet" id="cmdidAddFileDescription" priority="0x0100" type="Button">
        <Parent guid="guidSeriousMacroCmdSet" id="SubMenuGroup0" />
        <Icon guid="guidImages0" id="bmpLogo" />
        <Strings>
          <ButtonText>Add File Description</ButtonText>
        </Strings>
      </Button>
      <Button guid="guidSeriousMacroCmdSet" id="cmdidAddFunctionDescription" priority="0x0100" type="Button">
        <Parent guid="guidSeriousMacroCmdSet" id="SubMenuGroup0" />
        <Icon guid="guidImages0" id="bmpLogo" />
        <Strings>
          <ButtonText>Add Function Description</ButtonText>
        </Strings>
      </Button>
      ......
    </Buttons>
 
    <Bitmaps>
      <Bitmap guid="guidImages0" href="Resources\Logo.png" usedList="bmpLogo"/>
      <Bitmap guid="guidImages1" href="Resources\Images.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows"/>
    </Bitmaps>
  </Commands>
 
  <Symbols>
    <GuidSymbol name="guidSeriousMacroPkg" value="{af36e190-f215-4b41-844c-6faf693b83bb}" />
 
    <GuidSymbol name="guidSeriousMacroCmdSet" value="{7d68a40d-3d64-4f8f-838f-71f5f269309b}">
      <IDSymbol name="MainMenuGroup" value="0x1000" />
      <IDSymbol name="SubMenu" value="0x2000"/>
      <IDSymbol name="SubMenuGroup0" value="0x2001"/>
      <IDSymbol name="SubMenuGroup1" value="0x2002"/>
      <IDSymbol name="cmdidAddFileDescription" value="0x03000" />
      <IDSymbol name="cmdidAddFunctionDescription" value="0x03001" />
      ......
    </GuidSymbol>
 
    <GuidSymbol name="guidImages0" value="{7DCAECED-2080-4592-ABDE-ED8E7B43765C}" >
      <IDSymbol name="bmpLogo" value="1" />
    </GuidSymbol>
    <GuidSymbol name="guidImages1" value="{c4951360-61e1-4367-9267-8faa9901a095}" >
      <IDSymbol name="bmpPic1" value="1" />
      <IDSymbol name="bmpPic2" value="2" />
      ......
    </GuidSymbol>
  </Symbols>
 
</CommandTable>

SeriousMacroPackage.cs

namespace SeriousCode.SeriousMacro
{
    ......
    public sealed class SeriousMacroPackage : Package
    {
        ......
 
        protected override void Initialize()
        {
            base.Initialize();
 
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if ( null != mcs )
            {
                CommandID cmdAddFileDescription = new CommandID(GuidList.guidSeriousMacroCmdSet, (int)PkgCmdIDList.cmdidAddFileDescription);
                MenuCommand menuAddFileDescription = new MenuCommand(AddFileDescription, cmdAddFileDescription);
                mcs.AddCommand(menuAddFileDescription);
 
                CommandID cmdAddFunctionDescription = new CommandID(GuidList.guidSeriousMacroCmdSet, (int)PkgCmdIDList.cmdidAddFunctionDescription);
                MenuCommand menuAddFunctionDescription = new MenuCommand(AddFunctionDescription, cmdAddFunctionDescription);
                mcs.AddCommand(menuAddFunctionDescription);
 
                ......
            }
        }
 
        private void AddFileDescription(object sender, EventArgs e) { ...... }
        private void AddFunctionDescription(object sender, EventArgs e) { ...... }
    }
}

링크

kb/vspackage.txt · 마지막으로 수정됨: 2014/11/11 14:57 저자 excel96