Partilhar via


Solution3.Globals Property

Definition

Gets the Globals object that contains any variable values that may be saved in the solution (.sln) file, the project file, or 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.

Implements

Attributes

Examples

Sub GlobalsExample(ByVal dte As DTE2)  
    ' Add a global variable to a solution and display it.  
    ' Open a solution in Visual Studio before running this example.  
    Try  
        Dim soln As Solution3 =  _  
        CType(_applicationObject.Solution, Solution3)  
        Dim solnName As String = _  
        System.IO.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)  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
public void GlobalsExample(DTE2 dte)  
{  
    // Add a global variable to the solution and display it.   
    // Open a solution in Visual Studio before running this example.  
    try  
    {  
        Solution3 soln = (Solution3)_applicationObject.Solution;  
        string solnName =  
          System.IO.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);  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show("ERROR: " + ex);  
    }  
}  

Remarks

Globals may be associated with any automation client.

Applies to