We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

IVCCollection Interface

An IVCCollection object contains the functionality that can be exercised on a collections object.

Namespace:  Microsoft.VisualStudio.VCProjectEngine
Assembly:  Microsoft.VisualStudio.VCProjectEngine (in Microsoft.VisualStudio.VCProjectEngine.dll)

public interface IVCCollection : IEnumerable

The IVCCollection type exposes the following members.

Public propertyCountGets a value indicating the number of objects in the collection.
Public propertyVCProjectEngineGets an object pointer to the project engine.

Public methodGetEnumeratorReturns an enumerator for items in the collection.
Public methodItemSelects an item in the collection.

For example, the Files property of a VCFilter object is a collection of the files in a folder.

The following example demonstrates how to use the EnablePREfast and AdditionalOptions properties to set the /analyze:WX- switch. (Both properties are required to do this.) Specifying /analyze:WX- means that code analysis warnings will not be treated as errors when compiling with /WX. For more information, see /analyze (Code Analysis).

To run this example, enter and run this example as outlined in How to: Compile and Run the Automation Object Model Code Examples. Then, in the new instance of Visual Studio, load a Visual C++ project and use the Add-in Manager to activate the add-in.

// 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)
        VCProject prj;
        IVCCollection cfgs, tools;
        VCConfiguration cfg;
        VCCLCompilerTool tool;
        StringBuilder sb = new StringBuilder();

        prj = (Microsoft.VisualStudio.VCProjectEngine.VCProject)
        cfgs = 
        cfg = 
        tools = 
        tool = 
        sb.Length = 0;
        sb.Append("Current project PREfast setting: " +
          tool.EnablePREfast + Environment.NewLine);
        sb.Append("Flag: " + tool.AdditionalOptions);

        // 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-";
            // 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);
    catch (System.Exception errmsg)
        MessageBox.Show("ERROR! " + errmsg.Message);