How to: Brand a VSPackage (C#)

To appear in the Help About dialog box and the splash screen, VSPackages must implement the IVsInstalledProduct interface. Doing this provides the following information to Visual Studio:

  • Name

  • ID, such as serial or version number

  • Information

  • Logo icon

The following code is from the Reference.Package Sample (C#).

To implement the IVsInstalledProduct interface

  1. Add the InstalledProductRegistrationAttribute attribute to the class that implements the VSPackage. This class must derive from both Package and IVsInstalledProduct.

    [MsVsShell.InstalledProductRegistration( 
        true, null, null, null)]
    [MsVsShell.DefaultRegistryRoot(
        "Software\\Microsoft\\VisualStudio\\8.0")]
    [MsVsShell.PackageRegistration(UseManagedResourcesOnly = true)]
    [Guid("EEE474A0-083B-4e9c-B453-F6FCCEDA2577")]
    public class PackageSplashHelpAboutLoadKey : MsVsShell.Package, IVsInstalledProduct
    {
    

    The first argument, UseInterface, of the InstalledProductRegistrationAttribute attribute tells Visual Studio to use IVsInstalledProduct to obtain product information, instead of the InstalledProducts registry key. The remaining arguments select string resources to display the product name, details, and ID, respectively. However, because the first argument is true, the remaining arguments are null.

  2. Right-click IVsInstalledProduct, point to Implement Interface, and then click Implement Interface.

  3. Implement IVsInstalledProduct with the following code:

    public int IdBmpSplash(out uint pIdBmp)
    {
        pIdBmp = 300;
        return VSConstants.S_OK;
    }
    public int IdIcoLogoForAboutbox(out uint pIdIco)
    {
        pIdIco = 400;
        return VSConstants.S_OK;
    }
    public int OfficialName(out string pbstrName)
    {
        pbstrName = GetResourceString("@101");
        return VSConstants.S_OK;
    }
    public int ProductDetails(out string pbstrProductDetails)
    {
        pbstrProductDetails = GetResourceString("@102");
        return VSConstants.S_OK;
    }
    public int ProductID(out string pbstrPID)
    {
        pbstrPID = GetResourceString("@104");
        return VSConstants.S_OK;
    }
    public string GetResourceString(string resourceName)
    {
        string resourceValue;
        IVsResourceManager resourceManager = 
            (IVsResourceManager)GetService(typeof(SVsResourceManager));
        if (resourceManager == null)
        {
            throw new InvalidOperationException(
                "Could not get SVsResourceManager service. Make sure that the package is sited before calling this method");
        }
        Guid packageGuid = this.GetType().GUID;
        int hr = resourceManager.LoadResourceString(
            ref packageGuid, -1, resourceName, out resourceValue);
        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr);
        return resourceValue;
    }
    

    Visual Studio calls these methods to obtain information for branding the VSPackage. The GetResourceString method is used to localize this information.

    Note

    Code comments are deleted for brevity. You can find them in the Reference.Package Sample (C#).

To maintain the product information strings

  1. Double-click the .resx resource file associated with the VSPackage.

    The resource editor opens.

  2. Find or add the product name, information, and ID.

    The following resource strings are from the Reference.Package Sample (C#).

    • @101
      Package Splash screen and Help About Official Name (C#).

    • @102
      This package demonstrates how to display text and image in the splash screen and the help about.

    • @104
      8.0

  3. Select and edit this information as you want.

To maintain the product icons and bitmaps

  1. Add the bitmaps and icons to the project as project resources.

    For more information, see Adding and Editing Resources (Visual C#).

  2. Close the resource editor and reopen the .resx file in an xml or text editor.

    Note

    The resource editor has no support for assigning resource IDs to any items other than strings.

  3. Find or add the icon and bitmap resources to the .resx file. The following resources are from the Reference.Package Sample (C#).

    <data name="300" type="System.Resources.ResXFileRef, System.Windows.Forms">
        <value>GenericPackage.bmp;System.Drawing.Bitmap, System.Drawing,
            Version=2.0.0.0, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a</value>
    </data>
    <data name="400" type="System.Resources.ResXFileRef, System.Windows.Forms">
        <value>GenericPackage.ico;System.Drawing.Icon, System.Drawing,
            Version=2.0.0.0, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a</value>
    </data>
    

To test the Help About and splash screens

See Also

Other Resources

VSPackage Branding