Exemple #1
0
        private async Task <IVsPathContext> GetPathContextFromPackagesConfigAsync(
            MSBuildNuGetProject msbuildNuGetProject, CancellationToken token)
        {
            var packageReferences = await msbuildNuGetProject.GetInstalledPackagesAsync(token);

            // switch to a background thread to process packages data
            await TaskScheduler.Default;

            var trie = new PathLookupTrie <string>();

            foreach (var pid in packageReferences.Select(pr => pr.PackageIdentity))
            {
                var packageInstallPath = msbuildNuGetProject.FolderNuGetProject.GetInstalledPath(pid);
                if (string.IsNullOrEmpty(packageInstallPath))
                {
                    throw new KeyNotFoundException(string.Format(CultureInfo.CurrentCulture, VsResources.PathContext_PackageDirectoryNotFound, pid));
                }

                trie[packageInstallPath] = packageInstallPath;
            }

            var pathContext = GetSolutionPathContext();

            return(new VsIndexedPathContext(
                       pathContext.UserPackageFolder,
                       pathContext.FallbackPackageFolders.Cast <string>(),
                       trie,
                       _telemetryProvider));
        }
Exemple #2
0
        private async Task <IVsPathContext> GetPathContextFromAssetsFileAsync(
            BuildIntegratedNuGetProject buildIntegratedProject, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            var lockFile = await _getLockFileOrNullAsync(buildIntegratedProject);

            if ((lockFile?.PackageFolders?.Count ?? 0) == 0)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, VsResources.PathContext_LockFileError));
            }

            // The user packages folder is always the first package folder. Subsequent package folders are always
            // fallback package folders.
            var packageFolders = lockFile
                                 .PackageFolders
                                 .Select(lockFileItem => lockFileItem.Path)
                                 .ToList();

            var userPackageFolder      = packageFolders[0];
            var fallbackPackageFolders = packageFolders.Skip(1);

            if (lockFile.Libraries == null ||
                lockFile.Libraries.Count == 0)
            {
                return(new VsPathContext(userPackageFolder, fallbackPackageFolders, _telemetryProvider));
            }

            var fppr = new FallbackPackagePathResolver(userPackageFolder, fallbackPackageFolders);

            var trie = new PathLookupTrie <string>();

            foreach (var pid in lockFile
                     .Libraries
                     .Where(l => l.Type == LibraryType.Package)
                     .Select(l => new PackageIdentity(l.Name, l.Version)))
            {
                var packageInstallPath = fppr.GetPackageDirectory(pid.Id, pid.Version);
                if (string.IsNullOrEmpty(packageInstallPath))
                {
                    throw new KeyNotFoundException(string.Format(CultureInfo.CurrentCulture, VsResources.PathContext_PackageDirectoryNotFound, pid));
                }

                trie[packageInstallPath] = packageInstallPath;
            }

            return(new VsIndexedPathContext(
                       userPackageFolder,
                       fallbackPackageFolders,
                       trie,
                       _telemetryProvider));
        }
        public VsIndexedPathContext(
            string userPackageFolder,
            IEnumerable <string> fallbackPackageFolders,
            PathLookupTrie <string> index,
            INuGetTelemetryProvider telemetryProvider)
        {
            if (index == null)
            {
                throw new ArgumentNullException(nameof(index));
            }

            _userPackageFolder      = userPackageFolder ?? throw new ArgumentNullException(nameof(userPackageFolder));
            _fallbackPackageFolders = fallbackPackageFolders?.ToList() ?? throw new ArgumentNullException(nameof(fallbackPackageFolders));
            _referenceLookupIndex   = index ?? throw new ArgumentNullException(nameof(index));
            _telemetryProvider      = telemetryProvider ?? throw new ArgumentNullException(nameof(telemetryProvider));
        }