private void AddInFilePackageReferences() { _packageReferencesFromCsProj.Clear(); var xmlSer = new XmlSerializer(typeof(Generated.PackageReference)); foreach (XmlNode r in _xml.GetElementsByTagName(PackageReferenceElementTag)) { var packageRef = (Generated.PackageReference)xmlSer.Deserialize(new StringReader(StripOuterXmlNamespace(r))); if (!string.IsNullOrEmpty(packageRef.Include) && !string.IsNullOrEmpty(packageRef.Version)) { var candidateIdentity = new NuGetPackageIdentity(packageRef.Include, packageRef.Version); if (!_packageReferencesFromCsProj.Any(x => x.Id.Equals(candidateIdentity.Id, StringComparison.OrdinalIgnoreCase))) { if (!AllPackageReferences.Any(x => x.Identity == candidateIdentity)) { _packageReferencesFromCsProj.Add(candidateIdentity); } else { throw new Exceptions.DuplicatePackageReferenceException($"Can't add {candidateIdentity} as CsProj-package reference to the project {Name}, a reference to that package already exists"); } } else { throw new Exceptions.DuplicatePackageReferenceException($"Duplicate {PackageReferenceElementTag} element with id {packageRef.Include} in the project {Name}"); } } else { throw new Exceptions.InvalidPackageReferenceException($"Error in project {Name}, the element {r.OuterXml} doesn't have the Include or the Version attributes properly set."); } } }
public async Task <IPackageIdentity> FindInstalledAsync(string packageId, CancellationToken cancellationToken) { log.Debug($"Finding installed packages with id '{packageId}'."); IPackageIdentity result = null; await ReadPackageConfig( (package, context) => { if (string.Equals(package.PackageIdentity.Id, packageId, StringComparison.CurrentCultureIgnoreCase)) { result = new NuGetPackageIdentity(package.PackageIdentity); return(Task.FromResult(true)); } return(Task.FromResult(false)); }, cancellationToken ); return(result); }