Ejemplo n.º 1
0
        internal IDictionary <string, NuGetPackageNode> GetPackagesFromAssetsFile()
        {
            var lockFile       = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            var lockFileTarget = lockFile.GetTarget(NuGetFramework.Parse(TargetFramework), RuntimeIdentifier);

            if (lockFileTarget == null)
            {
                var targetString = string.IsNullOrEmpty(RuntimeIdentifier) ? TargetFramework : $"{TargetFramework}/{RuntimeIdentifier}";

                throw new Exception($"Missing target section {targetString} from assets file {AssetsFilePath}.  Ensure you have restored this project previously.");
            }

            Dictionary <string, NuGetPackageNode> packages = new Dictionary <string, NuGetPackageNode>(lockFileTarget.Libraries.Count, StringComparer.OrdinalIgnoreCase);

            foreach (var library in lockFileTarget.Libraries)
            {
                var dependencyIds = library.Dependencies.Select(d => d.Id);

                packages.Add(library.Name, new NuGetPackageNode(library.Name, library.Version.ToString(), dependencyIds));
            }

            // Connect the graph
            foreach (var package in packages.Values)
            {
                package.PopulateDependencies(packages, log);
            }

            return(packages);
        }
Ejemplo n.º 2
0
        private void GetFrameworkLibraries()
        {
            var lockFile       = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath);
            var lockFileTarget = lockFile.GetTarget(NuGetFramework.Parse(TargetFramework), RuntimeIdentifier);

            if (lockFileTarget == null)
            {
                var targetString = string.IsNullOrEmpty(RuntimeIdentifier) ? TargetFramework : $"{TargetFramework}/{RuntimeIdentifier}";

                throw new Exception($"Missing target section {targetString} from assets file {AssetsFilePath}. Ensure you have restored this project previously.");
            }

            var netCoreAppPackage = lockFileTarget.Libraries.Single(l => l.Name == "Microsoft.NETCore.App");

            Dictionary <string, LockFileTargetLibrary> packages = new Dictionary <string, LockFileTargetLibrary>(lockFileTarget.Libraries.Count, StringComparer.OrdinalIgnoreCase);

            foreach (var lib in lockFileTarget.Libraries)
            {
                packages.Add(lib.Name, lib);
            }

            var packageQueue = new Queue <LockFileTargetLibrary>();

            packageQueue.Enqueue(netCoreAppPackage);


            var libraries = new List <string>();

            while (packageQueue.Count > 0)
            {
                var package = packageQueue.Dequeue();
                foreach (var lib in package.RuntimeAssemblies)
                {
                    libraries.Add(lib.ToString());
                }

                foreach (var dep in package.Dependencies.Select(d => d.Id))
                {
                    packageQueue.Enqueue(packages[dep]);
                }
            }

            frameworkLibs = libraries.Select(l => Path.GetFileName(l)).ToList();
        }
Ejemplo n.º 3
0
        public override bool Execute()
        {
            var lockFile       = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath.ItemSpec);
            var lockFileTarget = lockFile.GetTarget(NuGetFramework.Parse(TargetFramework), RuntimeIdentifier);

            if (lockFileTarget == null)
            {
                var targetString = string.IsNullOrEmpty(RuntimeIdentifier) ? TargetFramework : $"{TargetFramework}/{RuntimeIdentifier}";

                throw new Exception($"Missing target section {targetString} from assets file {AssetsFilePath}. Ensure you have restored this project previously.");
            }

            Dictionary <string, LockFileTargetLibrary> packages = new Dictionary <string, LockFileTargetLibrary>(lockFileTarget.Libraries.Count, StringComparer.OrdinalIgnoreCase);

            foreach (var lib in lockFileTarget.Libraries)
            {
                packages.Add(lib.Name, lib);
            }

            HashSet <string> packageNames = new HashSet <string>(PackageNames);
            var rootPackages = lockFileTarget.Libraries.Where(l => packageNames.Contains(l.Name));

            var packageQueue = new Queue <LockFileTargetLibrary>(rootPackages);

            var libraries = new List <string>();

            while (packageQueue.Count > 0)
            {
                var package = packageQueue.Dequeue();
                foreach (var lib in package.RuntimeAssemblies)
                {
                    libraries.Add(lib.ToString());
                }

                foreach (var dep in package.Dependencies.Select(d => d.Id))
                {
                    packageQueue.Enqueue(packages[dep]);
                }
            }

            RuntimeLibraries = libraries.Select(l => new TaskItem(l)).ToArray();

            return(true);
        }
Ejemplo n.º 4
0
        internal IDictionary <string, NuGetPackageNode> GetPackagesFromAssetsFile()
        {
            Dictionary <string, NuGetPackageNode> packages = new Dictionary <string, NuGetPackageNode>(StringComparer.OrdinalIgnoreCase);

            if (string.IsNullOrEmpty(ProjectAssetsFile))
            {
                return(packages);
            }

            if (string.IsNullOrEmpty(TargetFramework))
            {
                Log.LogError($"{nameof(TargetFramework)} was not specified and is required when {nameof(ProjectAssetsFile)} is present.");
                return(packages);
            }

            var lockFile       = new LockFileCache(BuildEngine4).GetLockFile(ProjectAssetsFile);
            var lockFileTarget = lockFile.GetTarget(NuGetFramework.Parse(TargetFramework), RuntimeIdentifier);

            if (lockFileTarget == null)
            {
                var targetString = string.IsNullOrEmpty(RuntimeIdentifier) ? TargetFramework : $"{TargetFramework}/{RuntimeIdentifier}";
                Log.LogError($"Missing target section {targetString} from assets file {ProjectAssetsFile}.  Ensure you have restored this project previously.");
                return(packages);
            }

            foreach (var library in lockFileTarget.Libraries)
            {
                var parentNode = GetOrCreatePackageNode(packages, library.Name);

                foreach (var dependency in library.Dependencies)
                {
                    var childNode = GetOrCreatePackageNode(packages, dependency.Id);

                    parentNode.AddDependency(childNode);
                }
            }

            return(packages);
        }