Continuing from last time...

Most of the interesting stuff in the wizard generated package is in the VsPkg.cs file. You may notice that it contains a class that inherits from the Package class (more on this later) and has several attributes associated with it. In case you didn't know, attributes are a way of providing extra metadata in an assembly for other tools (or people for that matter) to consume/view. Here's why...when you want your package to load into Visual Studio, you have to have certain entries in the registry. You can enter these registry values manually, but there's no reason to go through that painful process. If you use the attributes provided in VSIP Extras, your package will get registered correctly simply by building your C# project. How you ask? Well, if you look at the properties of the C# project you created, you'll notice that we've inserted a Post-Build Event which calls a tool called VSIPRegPkg.exe. This tool (included with VSIP Extras) will correctly register your package if you use the attributes in VSIPHelper.dll. Infact, if there's an attribute that is not provided, you can inherit from RegistrationAttribute and write your own! (See ms-help://MS.VSCC.2003/MS.VSIP.2003/vsenvsdk/html/vsconHowToCreateRegistrationAttributeClass.htm for more details)

Now back to VsPkg.cs. You'll notice that the main class you have inherits from Microsoft.VisualStudio.VSIP.Helper.Package. This is probably the single most important element in VSIP Extras. It would be well worth your time if you plan on doing any work with VSIP to understand the Package class. The Package class implements IVsPackage, the main interface needed to load a package into Visual Studio. If you specified that you wanted a menu command in the package wizard, you should have an implementation of the Exec method. This is the method that gets called when you select your menu command. [The Exec command comes from the Package class inheriting IOleCommandTarget.]

Another interesting method is QueryStatus. This method gets called every time that the Visual Studio environment needs to know the state of your menu command. From this method, you can control when your command is visible, checked, enabled, etc.

The last really important thing to note about the package class is a method called GetService. (There is an example of a call to this method in Exec().) You use the GetService method to get to all of the services proffered by the Visual Studio environment as well as other packages.

You can find out more about the Package class by checking out the source code included with VSIP Extras in EnvSDK\common\VSIPHelper\Package.cs. I highly encourage you to check it out.