Share via


How to: Brand a VSPackage (C# and Visual Basic)

 

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

  • Name

  • ID, such as serial or version number

  • Information

  • Logo icon

The following code is from VSSDK Samples.

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.

    [InstalledProductRegistration(true, null, null, null)]
    [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\8.0")]
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [Guid("EEE474A0-083B-4e9c-B453-F6FCCEDA2577")]
    public sealed class PackageSplashHelpAboutLoadKey : 
        Package, IVsInstalledProduct
    
    <InstalledProductRegistration(True, Nothing, Nothing, Nothing)> _
    <DefaultRegistryRoot("Software\Microsoft\VisualStudio\8.0")> _
    <PackageRegistration(UseManagedResourcesOnly:=True)> _
    <Guid("EEE474A0-083B-4e9c-B453-F6FCCEDA2577")> _
    Public NotInheritable Class PackageSplashHelpAboutLoadKey
        Inherits Package
        Implements 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 by using 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;
    }
    
    Public Function IdBmpSplash(ByRef pIdBmp As UInteger) As Integer _
        Implements IVsInstalledProduct.IdBmpSplash
        pIdBmp = 300
        Return VSConstants.S_OK
    End Function
    Public Function IdIcoLogoForAboutbox(ByRef pIdIco As UInteger) As Integer _
        Implements IVsInstalledProduct.IdIcoLogoForAboutbox
        pIdIco = 400
        Return VSConstants.S_OK
    End Function
    Public Function OfficialName(ByRef pbstrName As String) As Integer _
        Implements IVsInstalledProduct.OfficialName
        pbstrName = GetResourceString("@101")
        Return VSConstants.S_OK
    End Function
    Public Function ProductDetails(ByRef pbstrProductDetails As String) As Integer _
        Implements IVsInstalledProduct.ProductDetails
        pbstrProductDetails = GetResourceString("@102")
        Return VSConstants.S_OK
    End Function
    Public Function ProductID(ByRef pbstrPID As String) As Integer _
        Implements IVsInstalledProduct.ProductID
        pbstrPID = GetResourceString("@104")
        Return VSConstants.S_OK
    End Function
    Public Function GetResourceString(ByVal resourceName As String) As String
        Dim resourceValue As String
        Dim resourceManager As IVsResourceManager = DirectCast(GetService(GetType(SVsResourceManager)), IVsResourceManager)
        If resourceManager Is Nothing Then
            Throw New InvalidOperationException("Could not get SVsResourceManager service. Make sure that the package is sited before calling this method")
        End If
        Dim packageGuid As Guid = Me.[GetType]().GUID
        Dim hr As Integer = resourceManager.LoadResourceString(packageGuid, -1, resourceName, resourceValue)
        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr)
        Return resourceValue
    End Function
    

    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 VSSDK Samples.

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 VSSDK Samples.

    • @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 NOT IN BUILD: 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 does not support assigning resource IDs to items other than strings.

  3. Find or add the icon and bitmap resources to the .resx file. The following resources are from VSSDK Samples.

    <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 About dialog box and splash screens

See Also

VSPackage Branding