NuGet.PackageReferenceFile.DeleteEntry C# (CSharp) Method

DeleteEntry() private method

private DeleteEntry ( System.Xml.Linq.XDocument document, string id, SemanticVersion version ) : bool
document System.Xml.Linq.XDocument
id string
version SemanticVersion
return bool
        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;
        }

Same methods

PackageReferenceFile::DeleteEntry ( string id, SemanticVersion version ) : bool

Usage Example

Example #1
0
 public void RemovePackage(IPackage package)
 {
     if (_packageReferenceFile.DeleteEntry(package.Id, package.Version))
     {
         // Remove the repository from the source
         SourceRepository.UnregisterRepository(_packageReferenceFile);
     }
 }
All Usage Examples Of NuGet.PackageReferenceFile::DeleteEntry