CSVSToolWindow Module: CSVSToolWindow Project Overview


VSPackages are software modules that make up and extend the Visual Studio
integrated development environment (IDE) by providing UI elements, services,
projects, editors, and designers. VSPackages are the principal architectural
unit of Visual Studio, and are the unit of deployment, licensing, and security
also. Visual Studio itself is written mostly as a collection of VSPackages.
This sample demonstrate how to use the the Visual Studio Integration Package
Wizard to create a simple VSPackage with a tool window that has a Windows Media
control on it.


VS 2008 SDK must be installed on the machine. You can download it from:

Otherwise the project may not be opened by Visual Studio.

If you run this project on a x64 OS, please also config the Debug tab of the project
Setting. Set the "Start external program" to
C:\Program Files(x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe

NOTE: The Package Load Failure Dialog occurs because there is no PLK(Package Load Key)
     Specified in this package. To obtain a PLK, please to go to WebSite:
     More info


A: How to Create a VSPackage

    1. Create a new project using Visual Studio Integration Package as template
       (New Project dialog box -> Other Project Types -> Extensibility).

    2. In the Location box, type the file path for your VSPackage.

    3. In the Name box, type the name for the solution and then click OK to start
       the wizard.

    3. On the Select a Programming Language page, select Visual C# and have the
       wizard generate a key.snk file to sign the assembly, then click Next.

    4. In the Basic VSPackage Information page, specify details about your
       VSPackage(Brand the VSPackage) and click Next.

    5. Select the Menu Command option to create a new command for the VSPackage and
       select Tool Window to create a tool window in this VSPackage. Then click Next.
       The new command is put at the top of the Tools menu.

    6. Type the name(All-In-One) and ID(cmdidToolWindow) for the new
       menu command in the text boxes, then click Next. The command ID is the name
       of a constant that represents this menu command in the generated code.
    7. Type the name(My Tool Window) and ID(cmdidMyTool) for new tool window in the
       text boxes, and click Next.

    8. Uncheck the Intergration Test Project and Unit Test Project, then click

B: Customize the ToolWindow

    1. In Solution Explorer, MyControls.cs in the WinForm Designer.
    2. Delete the ClickMe button and add the Windows Media control to MyControls.
    3. Set the Dock property to Fill.
C: Add a Toolbar to the Tool Window

    1. In Solution Explorer, open CSVSToolWindow.vsct.
       VSCT file stands for Visual Studio Command Table. This is an XML based file that
       describes the layout and appearance of command items for a VSPackage. Command
       items include buttons, combo boxes, menus, toolbars, and groups of command items.
    2. In the <Symbols> section, find the <GuidSymbol> node whose name attribute is
       guidCSVSToolWindowCmdSet. Add the following two <IDSymbol> elements to the list of
       <IDSymbol> elements in this node to define a toolbar and a toolbar group.

       <IDSymbol name="ToolbarID" value="0x1000" />
      <IDSymbol name="ToolbarGroupID" value="0x1001" />
    3. Just above the <Groups> section, create an empty <Menus> section, and create the
       following <Menu> element to define the toolbar that you declared in step 2.
       <Menu guid="guidCSVSToolWindowCmdSet" id="ToolbarID"
             priority="0x0000" type="ToolWindowToolbar">
         <Parent guid="guidCSVSToolWindowCmdSet" id="ToolbarID" />
           <ButtonText>Tool Window Toolbar</ButtonText>
           <CommandName>Tool Window Toolbar</CommandName>
   4. Add a new <Group> element to the <Groups> section to define the group that you
      declared in the <Symbols> section.
      <Group guid="guidCSVSToolWindowCmdSet" id="ToolbarGroupID"
        <Parent guid="guidCSVSToolWindowCmdSet" id="ToolbarID"/>
   5. Save CSVSToolWindow.vsct.
D: Add a Toolbar to the Tool Window

    1. In Solution Explorer, open CSVSToolWindow.vsct.
       VSCT file stands for Visual Studio Command Table. This is an XML based file that
       describes the layout and appearance of command items for a VSPackage. Command
       items include buttons, combo boxes, menus, toolbars, and groups of command items.
    2. In the <Symbols> section, declare the following commands just after the toolbar
       and toolbar group declarations.
       <IDSymbol name="cmdidWindowsMediaOpen" value="0x132" />
    3. In the <Buttons> section, a <Button> element is already present and it contains
       a definition forthe cmdidToolWindow command. Add one more <Button> element to
       define the cmdidWindowsMedia and cmdidWindowsMediaOpen commands.
       <Button guid="guidCSVSToolWindowCmdSet"
               id="cmdidWindowsMediaOpen" priority="0x0101"
         <Parent guid="guidCSVSToolWindowCmdSet"
         <Icon guid="guidImages" id="bmpPic1" />
           <ButtonText>Load File</ButtonText>
   4. Save and close CSVSToolWindow.vsct, open PkgCmdID.cs and add the following lines
      in the class just after the existing members
       public const int cmdidWindowsMediaOpen = 0x132;
       public const int ToolbarID = 0x1000;
   5. Save PkgCmdID.cs
E: Implement the Commands:

   1. In Solution Explorer, open MyToolWindow.cs, which contains the class for the tool
      window itself. Add the following code just after the existing using statements.
      using System.ComponentModel.Design;
   2. Add the following code to the constructor, just before the line that says
      control = new MyControl().
           // Create the toolbar.
           this.ToolBar = new CommandID(GuidList.guidCSVSToolWindowCmdSet,
           this.ToolBarLocation = (int)VSTWT_LOCATION.VSTWT_TOP;

           // Create the handlers for the toolbar commands.
           var mcs = GetService(typeof(IMenuCommandService))
               as OleMenuCommandService;
           if (null != mcs)
               var toolbarbtnCmdID = new CommandID(
               var menuItem = new MenuCommand(new EventHandler(
                   ButtonHandler), toolbarbtnCmdID);
   3. In Solution Explorer, right-click MyControl.cs, click View Code, and add the following
      code to the end of the file, just before the final two closing braces.Save and close
       public AxWMPLib.AxWindowsMediaPlayer MediaPlayer
            get { return axWindowsMediaPlayer1; }

   4. Open to MyToolWindow.cs, and add the following handler at the end of the class, just before
      the two final closing braces.
       private void ButtonHandler(object sender, EventArgs arguments)
           OpenFileDialog fd = new OpenFileDialog();
           fd.Filter = "media files |*.wmv;*.asf";
           fd.Multiselect = false;
           if (DialogResult.OK == fd.ShowDialog())
               control.MediaPlayer.URL = fd.FileName;
   5. Save all the files.

F: Testing the Tool Window

   1. Press F5 to open a new instance of the Visual Studio experimental build.
   2. On the View menu, point to Other Windows and then click My Tool Window.
   3. Click the Load File button on the Tool Window and Select a media file.



How to: Create VSPackages (C# and Visual Basic)

How to: Register a VSPackage (C#)

VSPackage Tutorial 1: How to Create a VSPackage

Designing XML Command Table (.Vsct) Files

Commands Element

KeyBindings Element

VSPackage Tutorial 2: How to Create a Tool Window

Creating a package with a simple command

Menus and comands in VS IDE