public void LoadsNuSpecWithNoNamespace() { var reader = new NuSpecReader(NoopLogger.Instance); var nuspec = reader.Read(new FileInfo(@"TestFiles\nuSpecs\dummy.csproj")); Assert.IsNotNull(nuspec); }
public void LoadsNuSpecWithNoNamespace() { var reader = new NuSpecReader(); var nuspec = reader.Read(new FileInfo(@"TestFiles\nuSpecs\dummy.csproj"), new Progress <string>()); Assert.IsNotNull(nuspec); }
public Task <IPackageNameSearchResult> GetPackageNamesAsync(string prefix, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { try { NuGetFramework targetFramework = NuGetFramework.Parse(queryConfiguration.CompatibiltyTarget); List <IPackageInfo> infos = new List <IPackageInfo>(); foreach (string path in _fileSystem.EnumerateDirectories(_feed, $"*{prefix}*", SearchOption.TopDirectoryOnly).Where(x => x.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) > -1)) { if (cancellationToken.IsCancellationRequested) { return null; } if (infos.Count >= queryConfiguration.MaxResults) { break; } foreach (string verDir in _fileSystem.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly)) { if (cancellationToken.IsCancellationRequested) { return null; } if (verDir == null || SemanticVersion.Parse(verDir) == null) { continue; } string nuspec = _fileSystem.EnumerateFiles(verDir, "*.nuspec", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (nuspec != null) { IPackageInfo info = NuSpecReader.Read(nuspec, FeedKind.Local); if (info != null && NuGetPackageMatcher.IsMatch(targetFramework, verDir, info, queryConfiguration, _fileSystem)) { infos.Add(info); if (infos.Count >= queryConfiguration.MaxResults) { break; } } } } } return new PackageNameSearchResult(infos.Select(x => x.Id).ToList(), FeedKind.Local); } catch { return PackageNameSearchResult.Failure; } }, cancellationToken)); }
public Task <IPackageVersionSearchResult> GetPackageVersionsAsync(string prefix, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { try { List <string> versions = new List <string>(); bool anyFound = false; foreach (string path in _fileSystem.EnumerateDirectories(_feed).Where(x => x.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) > -1)) { if (cancellationToken.IsCancellationRequested) { return PackageVersionSearchResult.Cancelled; } string nuspec = _fileSystem.EnumerateFiles(path, "*.nuspec", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (nuspec != null) { anyFound = true; IPackageInfo info = NuSpecReader.Read(nuspec, FeedKind.Local); if (info != null && string.Equals(info.Id, prefix, StringComparison.OrdinalIgnoreCase)) { versions.Add(info.Version); } } } if (anyFound) { return new PackageVersionSearchResult(versions, FeedKind.Local); } return PackageVersionSearchResult.Failure; } catch { return PackageVersionSearchResult.Failure; } }, cancellationToken)); }
public Task <IPackageInfo> GetPackageInfoAsync(string id, string version, IPackageQueryConfiguration queryConfiguration, CancellationToken cancellationToken) { return(Task.Run(() => { if (version != null) { string nuspec = Path.Combine(_feed, id, version, $"{id}.nuspec"); if (_fileSystem.FileExists(nuspec)) { return Task.FromResult(NuSpecReader.Read(nuspec, FeedKind.Local)); } else { return Task.FromResult <IPackageInfo>(null); } } else { string package = Path.Combine(_feed, id); string dir = _fileSystem.EnumerateDirectories(package).OrderByDescending(x => SemanticVersion.Parse(_fileSystem.GetDirectoryName(x))).FirstOrDefault(); if (dir == null) { return Task.FromResult <IPackageInfo>(null); } string nuspec = Path.Combine(dir, $"{id}.nuspec"); if (_fileSystem.FileExists(nuspec)) { return Task.FromResult(NuSpecReader.Read(nuspec, FeedKind.Local)); } else { return Task.FromResult <IPackageInfo>(null); } } }, cancellationToken)); }