Persisting user information in Visual Studio
Visual Studio offers a way to persist user information between sessions. This is done by using the Globals object located on the EnvDTE assembly.
The Globals object allows you to store, retrieve, enumerate and persist user information. So the next time the IDE is open this information is restored.
We can persist information at three different levels:
- VS or IDE
The information is stored in C:\Documents and Settings\<username>\Application Data\Microsoft\Visual Studio\extglobal.dat. These values are persisted each time VS is closed or a Save All operation occurs.
Snippet:
DTE.Globals["PropertyName"] = value;
DTE.Globals.set_VariablePersists("PropertyName", true);
The information is stored in the .sln file. These values are persisted when the solution file is saved.
Snippet:
solution.Globals["PropertyName"] = value;
solution.Globals.set_VariablePersists("PropertyName", true);
The information is stored in the project file. These values are persisted anytime a project is saved.
Snippet:
project.Globals["PropertyName"] = value;
project.Globals.set_VariablePersists("PropertyName", true);
One important thing is that Values to be stored must be strings, they cannot be objects or structures because these files are xml files.
Pablo