protected void PersistXMLFragments()
{
if (IsFlavorDirty() != 0)
{
var doc = new XmlDocument();
var root = doc.CreateElement("ROOT");
// We will need the list of configuration inside the loop, so get it before entering the loop
var count = new uint[1];
IVsCfg[] configs = null;
var hr = ConfigProvider.GetCfgs(0, null, count, null);
if (ErrorHandler.Succeeded(hr) && count[0] > 0)
{
configs = new IVsCfg[count[0]];
hr = ConfigProvider.GetCfgs((uint) configs.Length, configs, count, null);
if (ErrorHandler.Failed(hr))
count[0] = 0;
}
if (count[0] == 0)
configs = new IVsCfg[0];
// We need to loop through all the flavors
string flavorsGuid;
ErrorHandler.ThrowOnFailure(((IVsAggregatableProject) this).GetAggregateProjectTypeGuids(out flavorsGuid));
foreach (var flavor in Utilities.GuidsArrayFromSemicolonDelimitedStringOfGuids(flavorsGuid))
{
var outerHierarchy = InteropSafeIVsHierarchy as IPersistXMLFragment;
// First check the project
if (outerHierarchy != null)
{
// Retrieve the XML fragment
var fragment = string.Empty;
var flavorGuid = flavor;
ErrorHandler.ThrowOnFailure(outerHierarchy.Save(ref flavorGuid,
(uint) _PersistStorageType.PST_PROJECT_FILE, out fragment, 1));
if (!string.IsNullOrEmpty(fragment))
{
// Add the fragment to our XML
WrapXmlFragment(doc, root, flavor, null, fragment);
}
// While we don't yet support user files, our flavors might, so we will store that in the project file until then
// TODO: Refactor this code when we support user files
fragment = string.Empty;
ErrorHandler.ThrowOnFailure(outerHierarchy.Save(ref flavorGuid,
(uint) _PersistStorageType.PST_USER_FILE, out fragment, 1));
if (!string.IsNullOrEmpty(fragment))
{
// Add the fragment to our XML
var node = WrapXmlFragment(doc, root, flavor, null, fragment);
node.Attributes.Append(doc.CreateAttribute(ProjectFileConstants.User));
}
}
// Then look at the configurations
foreach (var config in configs)
{
// Get the fragment for this flavor/config pair
string fragment;
ErrorHandler.ThrowOnFailure(((ProjectConfig) config).GetXmlFragment(flavor,
_PersistStorageType.PST_PROJECT_FILE, out fragment));
if (!string.IsNullOrEmpty(fragment))
{
string configName;
ErrorHandler.ThrowOnFailure(config.get_DisplayName(out configName));
WrapXmlFragment(doc, root, flavor, configName, fragment);
}
}
}
if (root.ChildNodes != null && root.ChildNodes.Count > 0)
{
// Save our XML (this is only the non-build information for each flavor) in msbuild
SetProjectExtensions(ProjectFileConstants.VisualStudio, root.InnerXml);
}
}
}