You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SSMS 2017加载完成后自动加载DLL扩展及获取[ProvideAutoLoad]参数

Loading DLL Extensions in SSMS 2017: Answers to Your Questions

Hey Ron, let's tackle your two questions one by one—here's how to get your DLL extensions loaded properly in SSMS 2017:

1. Loading a DLL Extension After SSMS 2017 Finishes Starting Up

If you need a straightforward way to load your DLL once SSMS is fully up and running, you have two main options:

  • Manual Loading (Great for Testing)
    Once SSMS is open, head to Tools > Extensions and Updates. From the left pane, pick Installed > Manage Extensions, then click Install and select your DLL file. Restart SSMS, and your extension will be active. This is perfect for quick tests but requires manual steps each time.

  • Registry-Based Loading
    To avoid manual clicks, you can configure the Windows Registry to load your DLL automatically after SSMS starts. Navigate to this registry path:
    HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\14.0_Config\AddIns
    (Note: SSMS 2017 uses version 14.0, so that's why the path includes 14.0_Config.)

    Create a new subkey named after your extension, then add these string values to it:

    • LoadBehavior: Set to 3 (tells SSMS to load the extension on startup)
    • CommandLineSafe: Set to 0
    • Description: A short description of your extension
    • Name: Your extension's display name
    • Assembly: The full file path to your DLL (e.g., C:\SSMSExtensions\MyCustomExtension.dll)

    Keep in mind this loads the extension as SSMS starts—if you need it to trigger right after SSMS is fully loaded (not just during startup), jump to the second question's solution.

2. Automatically Loading the DLL Immediately After SSMS 2017 Fully Loads (With Event Registration)

To make your DLL load the moment SSMS finishes initializing all its core services, you'll use the ProvideAutoLoad attribute from the Visual Studio Shell framework (since SSMS 2017 is built on the VS 2017 shell). Here's how to do it:

Step-by-Step Implementation

  1. Reference Required Assemblies
    In your DLL project, add references to these SSMS/VS Shell assemblies:

    • Microsoft.SqlServer.Management.UI.VSIntegration.dll
    • Microsoft.VisualStudio.Shell.15.0.dll
  2. Use ProvideAutoLoad with the Correct GUID
    The key is to target the UI context that fires when SSMS is fully initialized. For SSMS 2017, use the ShellInitialized context GUID: {ADFC4E64-0397-11D1-9F4E-00A0C911004F}. This ensures your DLL loads only after SSMS has finished setting up its main window and core features.

    Here's a code example for your extension package class:

    using Microsoft.VisualStudio.Shell;
    using Microsoft.SqlServer.Management.UI.VSIntegration;
    using System.Windows.Forms;
    
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [ProvideAutoLoad("{ADFC4E64-0397-11D1-9F4E-00A0C911004F}")] // Triggers on full SSMS load
    [Guid("YOUR-EXTENSION-GUID-HERE")] // Replace with your own unique GUID
    public class MySSMSExtension : Package
    {
        protected override void Initialize()
        {
            base.Initialize();
            // This code runs right after SSMS is fully loaded
            // Add your extension logic here—register menus, tools, etc.
            MessageBox.Show("My extension loaded successfully after SSMS startup!");
        }
    }
    
  3. Deploy the DLL
    Compile your project, then place the DLL in SSMS's extension directory:
    C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Extensions
    Alternatively, use the registry method from question 1 to specify the DLL path.

Quick Verification

Add a simple MessageBox (like in the example) to the Initialize method. When you start SSMS, you'll see the pop-up right after the main window fully loads—confirming your DLL was loaded at the correct time.


内容的提问来源于stack exchange,提问作者ron

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:36:16