Partager via


_Solution.Globals Property

Definition

Gets the Globals that contains add-in values that may be saved in the solution (.sln) file, the project file, or in the user's profile data.

public:
 property EnvDTE::Globals ^ Globals { EnvDTE::Globals ^ get(); };
public:
 property EnvDTE::Globals ^ Globals { EnvDTE::Globals ^ get(); };
[System.Runtime.InteropServices.DispId(31)]
public EnvDTE.Globals Globals { [System.Runtime.InteropServices.DispId(31)] get; }
[<System.Runtime.InteropServices.DispId(31)>]
[<get: System.Runtime.InteropServices.DispId(31)>]
member this.Globals : EnvDTE.Globals
Public ReadOnly Property Globals As Globals

Property Value

A Globals object.

Attributes

Examples

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);  
}  

Remarks

The add-ins are available when the solution, project file, and so on is loaded.

Solution globals aren't necessarily add-in created; they can also be created by macros or any other automation client.

Note

VariableValue[] name strings cannot contain space, colon (:), or period(.) characters. If a name has any of these characters, you get the error, "Value does not fall within expected range."

Applies to