private Dictionary <CsProject, XmlDocument> CreatPackageReferenceContent(Dictionary <NuGetPackageInfo, SlnxHandler> debugItems) { _logger?.Info($"Adding nuget package references to the CsProjects..."); var ret = new Dictionary <CsProject, XmlDocument>(); foreach (var p in _slnx.project.Where(x => x.@ref?.Count() > 0)) { Assert(!p.name.Contains("*"), "Reference to projects with wildcards are not (yet?) supported"); var csProject = _projects.Where(x => x.Name == p.name).FirstOrDefault(); Assert(csProject != null, "The project {0} cannot be found in the list of known CsProjects", p.name); var xml = new XmlDocument(); var root = xml.CreateNode(XmlNodeType.Element, "Project", null); xml.AppendChild(root); var itemGroup = xml.CreateNode(XmlNodeType.Element, "ItemGroup", null); xml.DocumentElement.AppendChild(itemGroup); foreach (var r in p.@ref) { var refPackage = AllPackages.Where(x => x.Identity.Id.ToLower() == r.ToLower()).FirstOrDefault(); Assert(refPackage != null, "The project {0} has a reference to an unknown package {1}. Add it as <package> to the slnx file [{2}]", p.name, r, _slnxFile); AppendReference(debugItems, itemGroup, refPackage); csProject.AddPackageReference(refPackage); } ret.Add(csProject, xml); } return(ret); }
public async Task GetUpdates_IncludesSemVerV2PackageVersionsWhenSemVerLevel2OrHigher(string semVerLevel) { // Arrange const string currentVersionString = "1.0.0"; var currentVersion = NuGetVersion.Parse(currentVersionString); var expected = AllPackages.Where(p => NuGetVersion.Parse(p.Version) > currentVersion); // Act var resultSet = await GetCollection <V2FeedPackage>( (controller, options) => controller.GetUpdates(options, TestPackageId, currentVersionString, includePrerelease: true, includeAllVersions: true, semVerLevel: semVerLevel), $"/api/v2/GetUpdates()?packageIds='{TestPackageId}'&versions='{currentVersionString}'&includePrerelease=true&includeAllVersions=true&semVerLevel={semVerLevel}"); // Assert foreach (var package in SemVer2Packages.Where(p => NuGetVersion.Parse(p.Version) > currentVersion)) { // Assert all of the SemVer2 packages are included in the result. // Whilst at it, also check the NormalizedVersion on the OData feed. Assert.Single(resultSet.Where(feedPackage => string.Equals(feedPackage.Version, package.Version) && string.Equals(feedPackage.NormalizedVersion, package.NormalizedVersion) && string.Equals(feedPackage.Id, package.PackageRegistration.Id))); } foreach (var package in NonSemVer2Packages.Where(p => NuGetVersion.Parse(p.Version) > currentVersion)) { // Assert all of the non-SemVer2 packages are included in the result. // Whilst at it, also check the NormalizedVersion on the OData feed. Assert.Single(resultSet.Where(feedPackage => string.Equals(feedPackage.Version, package.Version) && string.Equals(feedPackage.NormalizedVersion, package.NormalizedVersion) && string.Equals(feedPackage.Id, package.PackageRegistration.Id))); } Assert.Equal(expected.Count(), resultSet.Count); }
public async Task SearchCount_IncludesSemVerV2PackageVersionsWhenSemVerLevel2OrHigher_ExcludePrerelease(string semVerLevel) { // Act var searchCount = await GetInt <V2FeedPackage>( async (controller, options) => await controller.SearchCount(options, _curatedFeedName, searchTerm: TestPackageId, semVerLevel: semVerLevel), $"/api/v2/curated-feed/{_curatedFeedName}/Search/$count?searchTerm='{TestPackageId}'&semVerLevel={semVerLevel}"); // Assert Assert.Equal(AllPackages.Where(p => !p.IsPrerelease).Count(), searchCount); }
public async Task Search_IncludesSemVerV2PackageVersionsWhenSemVerLevel2OrHigher_ExcludePrerelease(string semVerLevel) { // Act var resultSet = await GetCollection <V2FeedPackage>( async (controller, options) => await controller.Search(options, _curatedFeedName, searchTerm: TestPackageId, semVerLevel: semVerLevel), $"/api/v2/curated-feed/{_curatedFeedName}/Search?searchTerm='{TestPackageId}'&semVerLevel={semVerLevel}"); // Assert AssertSemVer2PackagesIncludedInResult(resultSet, includePrerelease: false); Assert.Equal(AllPackages.Where(p => !p.IsPrerelease).Count(), resultSet.Count); }
public override bool Execute() { var pkgPath = Package.ItemSpec; var defines = Defines.IsNullOrEmpty() ? new string[0] : Defines.Select(each => each.ItemSpec).ToArray(); try { using (var script = new PackageScript(pkgPath)) { if (PackageDirectory.Is()) { script.AddNuGetPackageDirectory(PackageDirectory.GetFullPath()); } if (defines != null) { foreach (var i in defines) { var p = i.IndexOf("="); var k = p > -1 ? i.Substring(0, p) : i; var v = p > -1 ? i.Substring(p + 1) : ""; script.AddMacro(k, v); } } script.Save(PackageTypes.NuGet, true); AllPackages = script.Packages.Select(each => (ITaskItem) new TaskItem(each)).ToArray(); RedistPackages = AllPackages.Where(each => each.ItemSpec.ToLower().IndexOf("redist") > -1).ToArray(); SymbolsPackages = AllPackages.Where(each => each.ItemSpec.ToLower().IndexOf("symbols") > -1).ToArray(); MainPackages = AllPackages.Where(each => each.ItemSpec.ToLower().IndexOf("redist") == -1 && each.ItemSpec.ToLower().IndexOf("symbols") == -1).ToArray(); foreach (var p in RedistPackages) { var n = Path.GetFileNameWithoutExtension(p.ItemSpec); var o = n.IndexOf(".redist."); p.SetMetadata("pkgIdentity", "{0} {1}".format(n.Substring(0, o + 7), n.Substring(o + 8))); } NuGetSuccess = true; return(true); } } catch { } NuGetSuccess = false; return(false); }
public async Task GetUpdatesCount_IncludesSemVerV2PackageVersionsWhenSemVerLevel2OrHigher(string semVerLevel) { // Arrange const string currentVersionString = "1.0.0"; var currentVersion = NuGetVersion.Parse(currentVersionString); var expected = AllPackages.Where(p => NuGetVersion.Parse(p.Version) > currentVersion); // Act var searchCount = await GetInt <V2FeedPackage>( (controller, options) => controller.GetUpdatesCount( options, packageIds: TestPackageId, versions: currentVersionString, includePrerelease: true, includeAllVersions: true, semVerLevel: semVerLevel), $"/api/v2/GetUpdates()?packageIds='{TestPackageId}'&versions='{currentVersionString}'&includePrerelease=true&includeAllVersions=true&semVerLevel={semVerLevel}"); // Assert Assert.Equal(expected.Count(), searchCount); }