示例#1
0
        public void GetBaseLinedDependenciesFromBaseLinePackages()
        {
            Dictionary <string, SortedSet <Version> > baseLineVersions = new Dictionary <string, SortedSet <Version> >();

            foreach (var baseLinePackage in BaseLinePackages.NullAsEmpty())
            {
                SortedSet <Version> versions = null;
                if (!baseLineVersions.TryGetValue(baseLinePackage.ItemSpec, out versions))
                {
                    baseLineVersions[baseLinePackage.ItemSpec] = versions = new SortedSet <Version>();
                }
                versions.Add(new Version(baseLinePackage.GetMetadata("Version")));
            }

            List <ITaskItem> baseLinedDependencies = new List <ITaskItem>();

            foreach (var dependency in OriginalDependencies)
            {
                if (Apply)
                {
                    SortedSet <Version> dependencyBaseLineVersions = null;
                    Version             requestedVersion           = null;
                    Version.TryParse(dependency.GetMetadata("Version"), out requestedVersion);

                    if (baseLineVersions.TryGetValue(dependency.ItemSpec, out dependencyBaseLineVersions))
                    {
                        // if no version is requested, choose the highest.  Otherwise choose the first that is
                        // greater than or equal to the version requested.
                        Version baseLineVersion = requestedVersion == null?
                                                  dependencyBaseLineVersions.Last() :
                                                      dependencyBaseLineVersions.FirstOrDefault(v => v >= requestedVersion);

                        if (baseLineVersion != null)
                        {
                            dependency.SetMetadata("Version", baseLineVersion.ToString(3));
                        }
                    }
                }

                baseLinedDependencies.Add(dependency);
            }

            BaseLinedDependencies = baseLinedDependencies.ToArray();
        }
        public override bool Execute()
        {
            Func <string, bool> isKnownPackage;

            if (PackageIndexes != null && PackageIndexes.Length > 0)
            {
                var index = PackageIndex.Load(PackageIndexes.Select(pi => pi.GetMetadata("FullPath")));
                isKnownPackage = packageId => index.Packages.ContainsKey(packageId);
            }
            else
            {
                var baseLinePackageIds = new HashSet <string>(BaseLinePackages.NullAsEmpty().Select(b => b.ItemSpec));
                isKnownPackage = packageId => baseLinePackageIds.Contains(packageId);
            }

            FilteredDependencies = OriginalDependencies.Where(
                dependency =>
                !dependency.ItemSpec.StartsWith("System.Private") ||      // only apply filtering to System.Private dependencies
                isKnownPackage(dependency.ItemSpec)
                ).ToArray();

            return(!Log.HasLoggedErrors);
        }