Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

For VS Extensions Proper Way to Store Data in Project File

$
0
0

What is the proper way to store persistent data in a project file?

I know that there is the EnvDTE.Project.Globals object, where an extension can set an attribute and have that save to the project file. Yes, one has to say that the data is persistent and then save the project file. The problem with this approach is that the the Globals object does not exist for F# projects and for all intent and purpose does not exist for C++ files (it is not null, but persistence does not work). Globals works nicely for C# and VB. Moreover, I do not like the way that Globals writes to the project file.

EnvDTE.Project oProject = dte.Solution.Projects.Item(1);
Globals oGlobals = oProject.Globals;
oGlobals["myvariableA"] = "asdf";
oGlobals.VariablePersists[propertyName] = true;

The final output would be:

<ProjectExtensions><VisualStudio><UserProperties myvariableA="assdf" /></VisualStudio></ProjectExtensions>

All extensions use the same block. My idea would be to place the data in some format like the following, which also does not cause  validation issues, if a user has the project open in the Visual Studio text editor.

<ProjectExtensions><VisualStudio><MyProject><MyProjectProperty1>3</MyProjectProperty><MyProjectProperty2>8</MyProjectProperty><MyProjectProperty3>2016</MyProjectProperty></MyProject></VisualStudio></ProjectExtensions>

I thought of using IPersistXMLFragment and IVsProjectFlavorCfg combinations, but this approach lacks the key concept of reading, writing, and removing the XML code from the project file. The IPersistXMLFragment load method takes XML code as a string, loads the values into a dictionary, and then manages the values. The save method does the reverse going from a management construct back to a string based version of XML. Missing, as I just said, is the read, write, and remove from the actual project file without manually editing the file and causing a project reload.

I was also playing with the IVsHierarchy and MSBuild VSIX interface/object, but did not get very far.

Does anyone have any ideas?




Viewing all articles
Browse latest Browse all 4410

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>