private static LocalPackageInfo?GetPackageInfo(InstalledPackageReference packageReference, IEnumerable <LockFileItem> folders)
        {
            var packageIdentity = new NuGet.Packaging.Core.PackageIdentity(packageReference.Name, packageReference.ResolvedVersion);

            foreach (var folder in folders)
            {
                var packageInfo = LocalFolderUtility.GetPackageV3(folder.Path, packageIdentity, Logger);
                return(packageInfo);
            }

            return(null);
        }
        public LocalPackageInfo FindPackage(string packageId, NuGetVersion version)
        {
            if (!Exists(packageId, version))
            {
                return(null);
            }

            //TODO resign from IFileSystem
            var    physicalFs = (PhysicalFileSystem)_fileSystem;
            string root       = physicalFs.Root;

            return(LocalFolderUtility.GetPackageV3(root, packageId, version, _logAdapter));
        }
Exemple #3
0
        private PackageInfo BuildPackageInfo(FeedType type, string rootPath, string id, NuGet.Versioning.NuGetVersion version, List <ProjectInfo> projects)
        {
            LocalPackageInfo localPackageInfo;

            switch (type)
            {
            case FeedType.FileSystemV2:
                localPackageInfo = LocalFolderUtility.GetPackageV2(rootPath, id, version, _logger);
                if (localPackageInfo == null)
                {
                    return(null);
                }
                return(new PackageInfo
                {
                    ProjectList = projects,
                    LocalPackageInfo = localPackageInfo
                });

            case FeedType.FileSystemV3:
                localPackageInfo = LocalFolderUtility.GetPackageV3(rootPath, id, version, _logger);
                if (localPackageInfo == null)
                {
                    return(null);
                }
                return
                    (new PackageInfo
                {
                    ProjectList = projects,
                    LocalPackageInfo = localPackageInfo
                });

            default:
            {
                Debug.WriteLine($"Unknown Type:{type}");
                return(null);
            }
            }
        }
Exemple #4
0
        public async Task DownloadPackages()
        {
            var mgr = Init();

            void ClearCache(string pkgName, NuGetVersion pkgVersion)
            {
                var pkg      = new PackageIdentity(pkgName, pkgVersion);
                var localPkg = LocalFolderUtility.GetPackageV3(SettingsUtility.GetGlobalPackagesFolder(mgr.NugetSettings), pkg, mgr.Logger);

                if (localPkg != null)
                {
                    Directory.Delete(Path.GetDirectoryName(localPkg.Path), true);
                }
            }

            // Remove "Microsoft.Quantum.Chemistry" and "Microsoft.Quantum.Research" from local cache,
            // Do this on an old version, to make sure we don't try to delete a loaded assembly:
            var version = NuGetVersion.Parse("0.3.1811.2802-preview ");

            ClearCache("Microsoft.Quantum.Chemistry", version);
            ClearCache("Microsoft.Quantum.Research", version);

            var researchPkg = new PackageIdentity("Microsoft.Quantum.Research", version);
            var chemPkg     = new PackageIdentity("Microsoft.Quantum.Chemistry", version);

            using (var context = new SourceCacheContext())
            {
                var dependencies = await mgr.GetPackageDependencies(researchPkg, context);

                Assert.IsFalse(mgr.IsInstalled(researchPkg));
                Assert.IsFalse(mgr.IsInstalled(chemPkg));

                await mgr.DownloadPackages(context, dependencies);

                Assert.IsTrue(mgr.IsInstalled(researchPkg));
                Assert.IsTrue(mgr.IsInstalled(chemPkg));
            }
        }
Exemple #5
0
        public List <Project> AnalyzeProject(string projectPath, bool includeTransitiveDependencies, int transitiveDepth)
        {
            var dependencyGraph = _dependencyGraphService.GenerateDependencyGraph(projectPath);

            if (dependencyGraph == null)
            {
                return(null);
            }

            var projects = new List <Project>();

            foreach (var packageSpec in dependencyGraph.Projects.Where(p => p.RestoreMetadata.ProjectStyle == ProjectStyle.PackageReference))
            {
                // Restore the packages
                _dotNetRestoreService.Restore(packageSpec.FilePath);

                // Load the lock file
                string lockFilePath = _fileSystem.Path.Combine(packageSpec.RestoreMetadata.OutputPath, "project.assets.json");
                var    lockFile     = LockFileUtilities.GetLockFile(lockFilePath, NullLogger.Instance);

                // Create a project
                var project = new Project(packageSpec.Name, packageSpec.FilePath, packageSpec.RestoreMetadata.Sources.Select(s => s.SourceUri).ToList(), packageSpec.Version);
                projects.Add(project);

                // Get the target frameworks with their dependencies
                foreach (var targetFrameworkInformation in packageSpec.TargetFrameworks)
                {
                    var targetFramework = new TargetFramework(targetFrameworkInformation.FrameworkName);
                    project.TargetFrameworks.Add(targetFramework);

                    var target = lockFile.Targets.FirstOrDefault(t => t.TargetFramework.Equals(targetFrameworkInformation.FrameworkName));

                    if (target != null)
                    {
                        foreach (var projectDependency in targetFrameworkInformation.Dependencies)
                        {
                            var projectLibrary = target.Libraries.FirstOrDefault(library => string.Equals(library.Name, projectDependency.Name, StringComparison.OrdinalIgnoreCase));

                            bool isDevelopmentDependency = false;
                            if (projectLibrary != null)
                            {
                                // Determine whether this is a development dependency
                                var packageIdentity = new PackageIdentity(projectLibrary.Name, projectLibrary.Version);
                                var packageInfo     = LocalFolderUtility.GetPackageV3(packageSpec.RestoreMetadata.PackagesPath, packageIdentity, NullLogger.Instance);
                                if (packageInfo != null)
                                {
                                    isDevelopmentDependency = packageInfo.GetReader().GetDevelopmentDependency();
                                }
                            }

                            var dependency = new Dependency(projectDependency.Name, projectDependency.LibraryRange.VersionRange, projectLibrary?.Version,
                                                            projectDependency.AutoReferenced, false, isDevelopmentDependency);
                            targetFramework.Dependencies.Add(dependency);

                            // Process transitive dependencies for the library
                            if (includeTransitiveDependencies)
                            {
                                AddDependencies(targetFramework, projectLibrary, target, 1, transitiveDepth);
                            }
                        }
                    }
                }
            }

            return(projects);
        }