다음을 통해 공유


설정 저장소에서 서비스 정보 가져오기

설정 저장소를 사용하여 사용 가능한 모든 서비스를 찾거나 특정 서비스가 설치되어 있는지 여부를 확인할 수 있습니다. 서비스 클래스의 유형을 알고 있어야 합니다.

사용 가능한 서비스를 나열하려면

  1. FindServicesExtension VSIX 프로젝트를 만든 다음, FindServicesCommand 사용자 지정 명령을 추가합니다. 사용자 지정 명령을 만드는 방법에 대한 자세한 내용은 메뉴 명령을 사용하여 확장 만들기를 참조하세요.

  2. FindServicesCommand.cs에서 다음 using 지시문을 추가합니다.

    using System.Collections.Generic;
    using Microsoft.VisualStudio.Settings;
    using Microsoft.VisualStudio.Shell.Settings;
    using System.Windows.Forms;
    
  3. 구성 설정 저장소를 가져옵니다. 그런 다음 Services라는 하위 컬렉션을 찾습니다. 이 컬렉션에는 사용 가능한 모든 서비스가 포함됩니다. MenuItemCommand 메서드에서 기존 코드를 제거하고 다음과 같이 바꿉니다.

    private void MenuItemCallback(object sender, EventArgs e)
    {
        SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider);
        SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration);
        string message = "Available services:\n";
        IEnumerable<string> collection = configurationSettingsStore.GetSubCollectionNames("Services");
        int n = 0;
        foreach (string service in collection)
        {
            message += configurationSettingsStore.GetString("Services\\" + service, "Name", "Unknown") + "\n";
        }
    
        MessageBox.Show(message);
    }
    
  4. 프로젝트를 빌드하고 디버깅을 시작합니다. 실험적 인스턴스가 나타납니다.

  5. 실험적 인스턴스에서 도구 메뉴의 Invoke FindServicesCommand를 클릭합니다.

    모든 서비스가 나열된 메시지 상자가 표시됩니다.

    이러한 설정을 확인하기 위해 레지스트리 편집기를 사용할 수 있습니다.

특정 서비스 찾기

또한 CollectionExists 메서드를 사용하여 특정 서비스가 설치되어 있는지 여부를 확인할 수도 있습니다. 서비스 클래스의 유형을 알고 있어야 합니다.

  1. 이전 프로시저에서 만든 프로젝트의 MenuItemCallback에서 서비스의 GUID로 명명된 하위 컬렉션이 있는 Services 컬렉션의 구성 설정 저장소를 검색합니다. 이런 경우 도움말 서비스를 찾아보세요.

    private void MenuItemCallback(object sender, EventArgs e)
    {
        SettingsManager settingsManager = new ShellSettingsManager(ServiceProvider);
        SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration);
        string helpServiceGUID = typeof(SVsHelpService).GUID.ToString("B").ToUpper();
        bool hasHelpService = configurationSettingsStore.CollectionExists("Services\\" + helpServiceGUID);
        string message = "Help Service Available: " + hasHelpService;
    
        MessageBox.Show(message);
    }
    
  2. 프로젝트를 빌드하고 디버깅을 시작합니다.

  3. 실험적 인스턴스에서 도구 메뉴의 Invoke FindServicesCommand를 클릭합니다.

    도움말 서비스 사용 가능:True 또는 False라는 메시지가 표시됩니다. 이 설정을 확인하려면 이전 단계에 표시된 대로 레지스트리 편집기를 사용할 수 있습니다.