Пример #1
0
        public static NuGet.IPackageConstraintProvider Provider([NotNull] this ConstraintProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (!provider.HasConstraints)
            {
                return(NuGet.NullConstraintProvider.Instance);
            }
            else
            {
                var res = new NuGet.DefaultConstraintProvider();
                foreach (var constraint in provider.Constraints)
                {
                    res.AddConstraint(constraint.Key, constraint.Value.ToVersionSpec());
                }
                return(res);
            }
        }
Пример #2
0
        /// <summary>
        /// Find the installed package <paramref name="packageId"/> using the version <paramref name="versionRange"/> if not null, otherwise the <paramref name="constraintProvider"/> if specified.
        /// If no constraints are specified, the first found entry, whatever it means for NuGet, is used.
        /// </summary>
        /// <param name="packageId">Name of the package.</param>
        /// <param name="versionRange">The version range.</param>
        /// <param name="constraintProvider">The package constraint provider.</param>
        /// <param name="allowPrereleaseVersions">if set to <c>true</c> [allow prelease version].</param>
        /// <param name="allowUnlisted">if set to <c>true</c> [allow unlisted].</param>
        /// <returns>A Package matching the search criterion or null if not found.</returns>
        /// <exception cref="System.ArgumentNullException">packageId</exception>
        /// <returns></returns>
        public NugetPackage FindLocalPackage(string packageId, PackageVersionRange versionRange = null, ConstraintProvider constraintProvider = null, bool allowPrereleaseVersions = true, bool allowUnlisted = false)
        {
            var package = manager.LocalRepository.FindPackage(packageId, versionRange?.ToVersionSpec(), constraintProvider?.Provider(), allowPrereleaseVersions, allowUnlisted);

            return(package != null ? new NugetPackage(package) : null);
        }