Source/Fuse/Tests/Solution/SolutionTestsHelper.cs
/// <summary>
/// Check all projects in solution at path for consistent nuget package references.
/// </summary>
/// <param name="solutionPath">Path to .sln file.</param>
Check all projects in solution at path for consistent nuget package references.
Check all projects in solution at path for consistent nuget package references .
public static void VerifyNugetPackageReferences(string solutionPath, Func<NugetPackageElement, bool> filter)
        {
            filter = filter ?? (x => true);
            var solutionDir = Path.GetDirectoryName(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);
        }
public static void VerifyNugetPackageReferences ( string solutionPath , Func < NugetPackageElement , bool > filter ) { filter = filter ?? ( x => true ) ; var solutionDir = Path . GetDirectoryName ( 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 ( " \r \n " , 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 ( " \r \n " , 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 ) , " \r \n " + sb ) ; }
Check all projects in solution at path for consistent nuget package references.
Check all projects in solution at path for consistent nuget package references .
//var solution = new ICSharpCode.NRefactory.ConsistencyCheck.Solution(solutionPath);
solutionPath
string
Path to .sln file.
Path to . sln file .
filter
Func<NugetPackageElement, bool>