public void All_uno_nuget_package_references_matches_version_specified_in_unoversion_file()
        {
            var unoversion = File.ReadAllText(Path.Combine(SolutionDirectory, ".unoversion")).Trim(" \t\r\n".ToCharArray());

            Assert.That(
                unoversion,
                Does.Match(@"^(?<numparts>\d+)(?:\.(?<numparts>\d+))*(?<suffix>-[\w\-]+)?$"),
                ".unoversion should contain a valid semantic version string");
            var wrongVersionSets = NugetPackageElement.Load(SolutionDirectory).Where(x => x.Id.StartsWith("FuseOpen.Uno."))
                                   .Where(x => x.Version != unoversion)
                                   .GroupBy(x => x.Version)
                                   .ToList();

            if (wrongVersionSets.Count > 0)
            {
                Console.WriteLine("Found one or more references to uno packages with wrong version:");
                foreach (var projGroup in wrongVersionSets.SelectMany(x => x).GroupBy(x => x.ProjectName))
                {
                    Console.WriteLine("{0}:", projGroup.Key);
                    foreach (var invalidRef in projGroup)
                    {
                        Console.WriteLine("  - {0}", invalidRef);
                    }
                }
            }

            Assert.That(wrongVersionSets, Is.Empty, "One or more references to the the wrong package version of uno found");
        }
Пример #2
0
        /// <summary>
        /// Check all projects in solution at path for consistent nuget package references.
        /// </summary>
        /// <param name="solutionPath">Path to .sln file.</param>
        public static void VerifyNugetPackageReferences(string solutionPath, Func <NugetPackageElement, bool> filter)
        {
            filter = filter ?? (x => true);
            var solutionDir = Path.GetDirectoryName(solutionPath);
            //var solution = new ICSharpCode.NRefactory.ConsistencyCheck.Solution(solutionPath);
            var           packages   = NugetPackageElement.Load(solutionDir).Where(filter).GroupBy(x => x.Id).ToList();
            StringBuilder sb         = new StringBuilder();
            int           errorCount = 0;

            foreach (var package in packages)
            {
                var versions = package.GroupBy(x => x.Version).ToList();
                if (versions.Count > 1)
                {
                    sb.AppendFormat("Found multiple versions of package {0}:\r\n{1}",
                                    package.Key,
                                    String.Join("",
                                                versions.Select(
                                                    x =>
                                                    $"    {x.Key}\r\n{String.Join("", x.Select(y => $"        {y.ProjectName}\r\n"))}")));

                    errorCount++;

                    var suggestedVersion =
                        versions.Select(x => x.Key).OrderBy(x => x).Last();
                    var suggestedUpgrades =
                        versions.Where(x => x.Key != suggestedVersion).SelectMany(x => x);
                    sb.AppendFormat("    Suggested version is {0}, install using:\r\n{1}",
                                    suggestedVersion,
                                    String.Join("",
                                                suggestedUpgrades.Select(
                                                    x =>
                                                    $"        Update-Package -Id {x.Id} -ProjectName {x.ProjectName} -Version {suggestedVersion}\r\n")));
                }
            }
            foreach (var item in packages.SelectMany(x => x))
            {
                errorCount += item.ValidateHintPathReference(sb);
            }
            Assert.That(errorCount, Is.EqualTo(0), "Found package reference inconsitencies:\r\n" + sb);
        }