_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)
Syntax
'Declaration
ReadOnly Property Globals As Globals
Globals Globals { get; }
property Globals^ Globals {
Globals^ get ();
}
abstract Globals : Globals with get
function get Globals () : Globals
Property Value
Type: EnvDTE.Globals
A Globals object.
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."
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);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Other Resources
How to: Compile and Run the Automation Object Model Code Examples