Exemple #1
0
        private static void ReplaceDependencyVersion(string ProjectDirectory, PackageDependency depPackage)
        {
            if (string.IsNullOrWhiteSpace(depPackage.RawVersion))
            {
                return;
            }

            string replaced = TryReplaceMacro(depPackage.RawVersion, ProjectDirectory);

            if (replaced != depPackage.RawVersion)
            {
                if (VersionSpecifier.TryParse(replaced, out var versionSpecifier))
                {
                    if (versionSpecifier.MatchBehavior.HasFlag(VersionMatchBehavior.Exact))
                    {
                        depPackage.Version = versionSpecifier;
                    }
                    else
                    {
                        depPackage.Version = new VersionSpecifier(versionSpecifier.Major,
                                                                  versionSpecifier.Minor,
                                                                  versionSpecifier.Patch,
                                                                  versionSpecifier.PreRelease,
                                                                  versionSpecifier.BuildMetadata,
                                                                  VersionMatchBehavior.Compatible | VersionMatchBehavior.AnyPrerelease);
                    }
                }
            }
        }
        private static VersionSpecifier ConvertVersion(string Version)
        {
            if (String.IsNullOrWhiteSpace(Version))
            {
                return(VersionSpecifier.Any);
            }
            if (VersionSpecifier.TryParse(Version, out var semver))
            {
                if (semver.MatchBehavior.HasFlag(VersionMatchBehavior.Exact))
                {
                    return(semver);
                }

                return(new VersionSpecifier(semver.Major,
                                            semver.Minor,
                                            semver.Patch,
                                            semver.PreRelease,
                                            semver.BuildMetadata,
                                            VersionMatchBehavior.Compatible | VersionMatchBehavior.AnyPrerelease));
            }
            // For compatability (pre 9.0 packages may not have correctly formatted version numbers)
            var plugins = PluginManager.GetPlugins <IVersionTryConverter>().Concat(PluginManager.GetPlugins <IVersionConverter>());

            foreach (var plugin in plugins.OrderBy(p => p.GetDisplayAttribute().Order))
            {
                try
                {
                    object cvt = Activator.CreateInstance(plugin);
                    if (cvt is IVersionTryConverter vc2)
                    {
                        if (vc2.TryConvert(Version, out SemanticVersion sv))
                        {
                            return(new VersionSpecifier(sv, VersionMatchBehavior.Compatible));
                        }
                    }
                    else if (cvt is IVersionConverter vc)
                    {
                        return(new VersionSpecifier(vc.Convert(Version), VersionMatchBehavior.Compatible));
                    }
                }
                catch
                {
                }
            }
            return(VersionSpecifier.Any);
        }