_Solution.Globals 属性

获取 Globals,它包含可以保存在解决方案 (.sln) 文件、项目文件或用户的配置文件数据中的外接程序值。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
ReadOnly Property Globals As Globals
Globals Globals { get; }
property Globals^ Globals {
    Globals^ get ();
}
abstract Globals : Globals with get
function get Globals () : Globals

属性值

类型:EnvDTE.Globals
一个 Globals 对象。

备注

在解决方案、项目文件等加载之后就可以使用外接程序。

Solution 全局变量不一定由外接程序创建;它们也可以由宏或任何其他自动化客户端创建。

备注

VariableValue 名称字符串不能包括空格、冒号 (:) 或句点 (.) 字符。如果名称包含任何这些字符,则会收到错误“值不在预期的范围内”。

示例

Sub GlobalsExample(ByVal dte As DTE2)

    ' NOTE: This example requires a reference to the
    '       System.IO namespace.

    ' Before running this example, open a solution.

    Dim soln As Solution = dte.Solution
    Dim solnName As String = _
        Path.GetFileNameWithoutExtension(soln.FullName)

    Dim globals As String

    MsgBox("Adding global variable TempGlobal = ""TempValue""")

    soln.Globals.VariableValue("TempGlobal") = "TempValue"

    Dim names() As Object = CType(soln.Globals.VariableNames, Object())
    Dim name As String

    For Each name In names
        globals &= "    " & name & " = """ & _
            soln.Globals.VariableValue(name).ToString() & """" & vbCrLf
    Next

    MsgBox("Solution " & solnName & _
        " has the following global variables:" & _
        vbCrLf & vbCrLf & globals)

End Sub
public void GlobalsExample(DTE2 dte)
{

    // NOTE: This example requires a reference to the
    //       System.IO namespace.

    // Before running this example, open a solution.

    Solution soln = dte.Solution;
    string solnName = Path.GetFileNameWithoutExtension(soln.FullName);

    MessageBox.Show(
        "Adding global variable TempGlobal = \"TempValue\"");

    soln.Globals["TempGlobal"] = "TempValue";

    object[] names = (object[])soln.Globals.VariableNames;
    string globals = "";

    foreach (string name in names)
        globals += "    " + name + " = \"" + 
            soln.Globals[name].ToString() + "\"\n";

    MessageBox.Show("Solution " + solnName + 
        " has the following global variables:\n\n" + globals);
}

.NET Framework 安全性

请参阅

参考

_Solution 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例