Ejemplo n.º 1
0
        public override bool Execute()
        {
            log = new MSBuildLog(Log);

            // Build the package graph
            var packages = GetPackagesFromAssetsFile();

            // Build file graph
            var files = GetFiles(packages);

            var trimmable = new Trimmable(TrimmablePackages?.Select(i => i.ItemSpec),
                                          TrimmableFiles?.Select(i => GetFileNameFromItem(i)));

            Queue <NuGetPackageNode> packageRoots = GetPackageRoots(packages, trimmable);
            Queue <FileNode>         fileRoots    = GetFileRoots(files, trimmable);

            while (packageRoots.Count > 0 || fileRoots.Count > 0)
            {
                while (fileRoots.Count > 0)
                {
                    var fileNode = fileRoots.Dequeue();

                    foreach (var file in fileNode.Dependencies.Where(f => !trimmable.IsFileTrimmable(f.Name)))
                    {
                        IncludeNode(fileRoots, file);
                    }

                    if (fileNode.Package != null && !trimmable.IsPackageTrimmable(fileNode.PackageId))
                    {
                        IncludeNode(packageRoots, fileNode.Package);
                    }
                }

                while (packageRoots.Count > 0)
                {
                    var packageNode = packageRoots.Dequeue();

                    foreach (var dependency in packageNode.Dependencies.Where(d => !trimmable.IsPackageTrimmable(d.Id)))
                    {
                        IncludeNode(packageRoots, dependency);
                    }

                    foreach (var file in packageNode.Files.Where(f => !trimmable.IsFileTrimmable(f.Name)))
                    {
                        IncludeNode(fileRoots, file);
                    }
                }
            }

            var excludedItems = files.Values.Where(f => !f.IsIncluded).Select(f => f.OriginalItem);

            TrimmedItems = excludedItems.ToArray();
            RuntimeItemsAfterTrimming = RuntimeItems.Except(excludedItems).ToArray();

            LogResults(files.Values);

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 2
0
        Queue <NuGetPackageNode> GetPackageRoots(IDictionary <string, NuGetPackageNode> packages, Trimmable trimmable)
        {
            var packageRootQueue = new Queue <NuGetPackageNode>();

            if (RootPackages != null)
            {
                var rootPackageIds = RootPackages.Select(i => GetPackageIdFromItemSpec(i.ItemSpec));

                var trimmedRootPackageIds = rootPackageIds.Where(p => !trimmable.IsPackageTrimmable(p));

                foreach (var rootPackageId in trimmedRootPackageIds)
                {
                    NuGetPackageNode rootPackage;

                    if (!packages.TryGetValue(rootPackageId, out rootPackage))
                    {
                        throw new Exception($"Root package {rootPackageId} was specified but was not found in {AssetsFilePath}");
                    }

                    IncludeNode(packageRootQueue, rootPackage);
                }
            }

            return(packageRootQueue);
        }
Ejemplo n.º 3
0
 private bool IsPackageTrimmable(NuGetPackageNode package)
 {
     return(TreatAllPackagesAsTrimmable ||
            trimmable.IsPackageTrimmable(package.Id) ||
            (TreatMetaPackagesAsTrimmable && package.IsMetaPackage) ||
            (TreatMultiPackagesAsTrimmable && package.IsMultiPackage && package.Files.Any(f => !f.IsIncluded)));
 }
Ejemplo n.º 4
0
 private bool IsPackageTrimmable(NuGetPackageNode package)
 {
     return(trimmable.IsPackageTrimmable(package.Id) ||
            (TreatMetaPackagesAsTrimmable && package.IsMetaPackage));
 }