Solution2.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)  
    ' Adds a global variable to a solution and  
    ' displays it.  
    ' Open a solution in   
    ' Visual Studio before running this example.  
    Try  
        Dim soln As Solution2 =  _  
        CType(_applicationObject.Solution, Solution2)  
        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  
//you will need to add this reference to your project as well  
using System.Windows.Forms;  
public void GlobalsExample(DTE2 dte)  
{  
    // Adds a global variable to the solution and displays it.   
    // Open a solution in Visual Studio before running this example.  
    try  
    {  
        Solution2 soln = (Solution2)_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