Share via


Interfaccia IVCCollection

IVCCollection l'oggetto contiene la funzionalità che può essere utilizzata su un oggetto collection.

Spazio dei nomi:  Microsoft.VisualStudio.VCProjectEngine
Assembly:  Microsoft.VisualStudio.VCProjectEngine (in Microsoft.VisualStudio.VCProjectEngine.dll)

Sintassi

'Dichiarazione
<GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")> _
Public Interface IVCCollection _
    Inherits IEnumerable
[GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")]
public interface IVCCollection : IEnumerable
[GuidAttribute(L"F34846C1-D08D-4359-907E-0EE22987618B")]
public interface class IVCCollection : IEnumerable
[<GuidAttribute("F34846C1-D08D-4359-907E-0EE22987618B")>]
type IVCCollection =  
    interface
        interface IEnumerable
    end
public interface IVCCollection extends IEnumerable

Il tipo IVCCollection espone i seguenti membri.

Proprietà

  Nome Descrizione
Proprietà pubblica Count Ottiene un valore che indica il numero di oggetti nella raccolta.
Proprietà pubblica VCProjectEngine Ottiene un puntatore al motore di progetto.

In alto

Metodi

  Nome Descrizione
Metodo pubblico GetEnumerator Restituisce un enumeratore per gli elementi della raccolta.
Metodo pubblico Item Selezionare un elemento nella raccolta.

In alto

Note

Ad esempio, Files proprietà di un oggetto VCFilter l'oggetto rappresenta una raccolta di file in una cartella.

Esempi

Nell'esempio seguente viene illustrato come utilizzare EnablePREfast e AdditionalOptions proprietà per impostare /analyze:WX- opzione.(Entrambe le proprietà sono necessarie questo scopo.) specificare /analyze:WX- indica che gli avvisi di analisi codice non verranno considerati come errori durante la compilazione con /WX.Per ulteriori informazioni, vedere /analyze (Analisi codice).

Per eseguire questo esempio, immettere ed eseguire l'esempio come descritto in Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.Quindi, nella nuova istanza di Visual Studio, caricare un oggetto Visual C++ progetto e utilizzare la Gestione componenti aggiuntivi attivare il componente aggiuntivo.

' Add reference to Microsoft.VisualStudio.VCProjectEngine.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports Microsoft.VisualStudio.VCProjectEngine
Imports System.Text

Sub EnablePREfastExample(ByVal dte As DTE2)
    Dim prj As VCProject
    Dim cfgs, tools As IVCCollection
    Dim cfg As VCConfiguration
    Dim tool As VCCLCompilerTool
    Dim sb As New StringBuilder

    prj = CType(dte.Solution.Projects.Item(1).Object, _
      Microsoft.VisualStudio.VCProjectEngine.VCProject)
    cfgs = CType(prj.Configurations, _
      Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
    cfg = CType(cfgs.Item(1), _
      Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
    tool = CType(cfg.Tools("VCCLCompilerTool"), _
      Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)

    sb.Length = 0
    sb.Append("Current project PREfast setting: " _
      & tool.EnablePREfast & Environment.NewLine)
    sb.Append("Flag: " & tool.AdditionalOptions)
    MsgBox(sb.ToString)

    ' Toggle PREfast setting.
    If Not (tool.EnablePREfast = True) Then
        ' PREfast is not enabled. Turn it and the WX- flag on.
        tool.EnablePREfast = True
        tool.AdditionalOptions = "/analyze:WX-"
    Else
        ' Toggle the opposite.
        tool.EnablePREfast = False
        tool.AdditionalOptions = "/analyze:WX"
    End If
    sb.Length = 0
    sb.Append("New project PREfast setting: " _
      & tool.EnablePREfast & Environment.NewLine)
    sb.Append("Flag: " & tool.AdditionalOptions)
    MsgBox(sb.ToString)
End Sub
// Add references to Microsoft.VisualStudio.VCProjectEngine and 
// System.Windows.Forms.
using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.VCProjectEngine;
using System.Text;
using System.Windows.Forms;

public void EnablePREfastExample(DTE2 dte)
{
    try
    {
        VCProject prj;
        IVCCollection cfgs, tools;
        VCConfiguration cfg;
        VCCLCompilerTool tool;
        StringBuilder sb = new StringBuilder();

        prj = (Microsoft.VisualStudio.VCProjectEngine.VCProject)
          dte.Solution.Projects.Item(1).Object;
        cfgs = 
          (Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
          prj.Configurations;
        cfg = 
          (Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
           cfgs.Item(1);
        tools = 
          (Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
          cfg.Tools;
        tool = 
          (Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
          tools.Item("VCCLCompilerTool");
                                
        sb.Length = 0;
        sb.Append("Current project PREfast setting: " +
          tool.EnablePREfast + Environment.NewLine);
        sb.Append("Flag: " + tool.AdditionalOptions);
        MessageBox.Show(sb.ToString());

        // Toggle PREfast setting.
        if (!(tool.EnablePREfast == true))
        {
            // PREfast is not enabled. Turn it and the WX- flag on.
            tool.EnablePREfast = true;
            tool.AdditionalOptions = "/analyze:WX-";
        }
        else
        {
            // Toggle the opposite.
            tool.EnablePREfast = false;
            tool.AdditionalOptions = "/analyze:WX";
        }
        sb.Length = 0;
        sb.Append("New project PREfast setting: " +
          tool.EnablePREfast + Environment.NewLine);
        sb.Append("Flag: " + tool.AdditionalOptions);
        MessageBox.Show(sb.ToString());
    }
    catch (System.Exception errmsg)
    {
        MessageBox.Show("ERROR! " + errmsg.Message);
    }
}

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.VisualStudio.VCProjectEngine

Altre risorse

Valori di HRESULT restituiti dal modello di progetto

Modello a oggetti Extensibility di Visual C++