private bool DeleteEntry(XDocument document, string id, SemanticVersion version)
{
XElement element = FindEntry(document, id, version);
if (element != null)
{
// Preserve the allowedVersions attribute for this package id (if any defined)
var versionConstraint = element.GetOptionalAttributeValue("allowedVersions");
if (!String.IsNullOrEmpty(versionConstraint))
{
_constraints[id] = versionConstraint;
}
// Remove the element from the xml dom
element.Remove();
// Always try and save the document, this works around a source control issue for solution-level packages.config.
SaveDocument(document);
if (!document.Root.HasElements)
{
// Remove the file if there are no more elements
FileSystem.DeleteFile(_path);
return true;
}
}
return false;
}