// parse the list of installed packages private IEnumerable<PackageBase> GetInstalledPackagesOptionValue() { // get possible installed packages var installedPackages = GetOptionValues("InstalledPackages") ?? new string[0]; // parse the installed package options passed in foreach (var installedPackage in installedPackages) { // we assume that the name passed in is something like jquery#1.2.5 string[] nameAndVersion = installedPackage.Split(new[] { "!#!" }, StringSplitOptions.None); var package = new PackageBase(); // only name passed in, no version if (nameAndVersion.Count() == 1) { package.Id = nameAndVersion[0]; yield return package; } else if (nameAndVersion.Count() == 2) { // this means there is version SemanticVersion semVers = null; try { // convert version to semvers semVers = new SemanticVersion(nameAndVersion[1]); } catch { // not a valid version, ignores this entry continue; } // set name and version of this installed packages package.Id = nameAndVersion[0]; package.Version = semVers.Version.ToStringSafe(); yield return package; } } }
internal bool MinAndMaxVersionMatched(SemanticVersion packageVersion, string minimumVersion, string maximumVersion, bool minInclusive, bool maxInclusive) { if (!string.IsNullOrWhiteSpace(minimumVersion)) { // Check whether we are checking for min inclusive version if (minInclusive) { // version too small, not what we are looking for if (packageVersion < new SemanticVersion(minimumVersion)) { return false; } } else { if (packageVersion <= new SemanticVersion(minimumVersion)) { return false; } } } if (!string.IsNullOrWhiteSpace(maximumVersion)) { // Check whether we are checking for max inclusive version if (maxInclusive) { // version too big, not what we are looking for if (packageVersion > new SemanticVersion(maximumVersion)) { return false; } } else { if (packageVersion >= new SemanticVersion(maximumVersion)) { return false; } } } return true; }