IVCCollection 接口
IVCCollection 对象包含可以在集合对象上运用的功能。
命名空间: Microsoft.VisualStudio.VCProjectEngine
程序集: Microsoft.VisualStudio.VCProjectEngine(在 Microsoft.VisualStudio.VCProjectEngine.dll 中)
语法
声明
<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
IVCCollection 类型公开以下成员。
属性
名称 | 说明 | |
---|---|---|
Count | 获取一个值,该值指示集合中对象的数目。 | |
VCProjectEngine | 具有对象指向项目引擎的指针。 |
页首
方法
名称 | 说明 | |
---|---|---|
GetEnumerator | 返回集合中项的枚举数。 | |
Item | 选择该集合中的项目。 |
页首
备注
例如, VCFilter 对象的 Files 属性是文件的集合文件夹中。
示例
下面的示例演示如何使用 EnablePREfast 和 AdditionalOptions 属性设置 /analyze:WX- 开关。 (需要两个属性。) 指定 /analyze:WX- 意味着代码分析警告不被视为错误,则编译 /WX时。 有关更多信息,请参见 /analyze(代码分析)。
如 如何:编译和运行自动化对象模型代码示例所述,若要运行此示例中,输入并运行此示例。 然后,在 Visual Studio新实例,加载一个 Visual C++ 项目并使用外接程序管理器激活外接程序。
' 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);
}
}
请参见
参考
Microsoft.VisualStudio.VCProjectEngine 命名空间