Export (0) Print
Expand All

_Solution.Globals Property

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.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Globals Globals { get; }

Property Value

Type: EnvDTE.Globals
A Globals object.

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.

NoteNote

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."

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

Show:
© 2014 Microsoft