Condividi tramite


Verificare i sottotipi di un progetto in fase di esecuzione

Un VSPackage che dipende da un sottotipo di progetto personalizzato deve includere la logica per cercare tale sottotipo in modo che possa non riuscire correttamente se il sottotipo non è presente. La procedura seguente illustra come verificare la presenza di un sottotipo specificato.

Per verificare la presenza di un sottotipo

  1. Ottenere la gerarchia del progetto dagli oggetti progetto e soluzione come IVsHierarchy oggetto aggiungendo il codice seguente al pacchetto VSPackage.

    EnvDTE.DTE dte;
    dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
    
    EnvDTE.Project project;
    project = dte.Solution.Projects.Item(1);
    
    IVsSolution solution;
    solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
    
    IVsHierarchy hierarchy;
    hierarchy = solution.GetProjectOfUniqueName(project.UniqueName);
    
    
  2. Eseguire il cast della gerarchia nell'interfaccia IVsAggregatableProjectCorrected .

    IVsAggregatableProjectCorrected AP;
    AP = hierarchy as IVsAggregatableProjectCorrected;
    
    
  3. Ottenere l'elenco dei GUID di tipo di progetto richiamando .GetAggregateProjectTypeGuids

    string projTypeGuids = AP.GetAggregateProjectTypeGuids().ToUpper();
    
    
  4. Controllare l'elenco per il GUID del sottotipo specificato.

    // Replace the string "MyGUID" with the GUID of the subtype.
    string guidMySubtype = "MyGUID";
    if (projTypeGuids.IndexOf(guidMySubtype) > 0)
    {
        // The specified subtype is present.
    }