public async Task InstallPackageAsync(
            Project project,
            string packageId,
            string version,
            string framework)
        {
            var packageIdentity    = new PackageIdentity(packageId, NuGetVersion.Parse(version));
            var settings           = Settings.LoadDefaultSettings(root: null);
            var sourceRepoProvider = new SourceRepositoryProvider(settings, Repository.Provider.GetCoreV3());
            var nuGetFramework     = NuGetFramework.ParseFolder(framework);
            var logger             = NullLogger.Instance;

            using (var cacheContext = new SourceCacheContext())
            {
                var repositories      = sourceRepoProvider.GetRepositories();
                var availablePackages = new HashSet <SourcePackageDependencyInfo>(PackageIdentityComparer.Default);

                // This will cache the dependencies.
                await GetPackageDependencies(
                    packageIdentity,
                    nuGetFramework,
                    cacheContext,
                    logger,
                    repositories,
                    availablePackages)
                .ConfigureAwait(false);

                var resolverContext = new PackageResolverContext(
                    dependencyBehavior: DependencyBehavior.Lowest,
                    targetIds: new[] { packageId },
                    requiredPackageIds: Enumerable.Empty <string>(),
                    packagesConfig: Enumerable.Empty <PackageReference>(),
                    preferredVersions: Enumerable.Empty <PackageIdentity>(),
                    availablePackages: availablePackages,
                    packageSources: sourceRepoProvider
                    .GetRepositories()
                    .Select(s => s.PackageSource),
                    log: logger);

                var resolver          = new PackageResolver();
                var packagesToInstall = resolver.Resolve(
                    resolverContext,
                    CancellationToken.None)
                                        .Select(
                    p => availablePackages.Single(
                        x => PackageIdentityComparer.Default.Equals(x, p)));

                var packagePathResolver   = new PackagePathResolver(Path.GetFullPath("packages"));
                var packageExtractContext = new PackageExtractionContext(
                    PackageSaveMode.Defaultv3,
                    XmlDocFileSaveMode.None,
                    ClientPolicyContext.GetClientPolicy(settings, logger),
                    //new PackageSignatureVerifier(
                    //new[] { new SignatureTrustAndValidityVerificationProvider() as ISignatureVerificationProvider }),
                    //SignatureVerificationProviderFactory.GetSignatureVerificationProviders()),
                    logger);
                var frameworkReducer = new FrameworkReducer();

                foreach (var packageToInstall in packagesToInstall)
                {
                    PackageReaderBase packageReader;
                    var installedPath = packagePathResolver.GetInstallPath(packageToInstall);

                    if (installedPath == null)
                    {
                        var downloadResource = await packageToInstall.Source
                                               .GetResourceAsync <DownloadResource>(CancellationToken.None)
                                               .ConfigureAwait(false);

                        var downloadResult = await downloadResource.GetDownloadResourceResultAsync(
                            packageToInstall,
                            new PackageDownloadContext(cacheContext),
                            SettingsUtility.GetGlobalPackagesFolder(settings),
                            logger,
                            CancellationToken.None)
                                             .ConfigureAwait(false);

                        await PackageExtractor.ExtractPackageAsync(
                            downloadResult.PackageSource,
                            downloadResult.PackageStream,
                            packagePathResolver,
                            packageExtractContext,
                            CancellationToken.None)
                        .ConfigureAwait(false);

                        packageReader = downloadResult.PackageReader;
                    }
                    else
                    {
                        packageReader = new PackageFolderReader(installedPath);
                    }

                    var libtItems = packageReader.GetLibItems();
                    var nearest   = frameworkReducer.GetNearest(
                        nuGetFramework,
                        libtItems.Select(x => x.TargetFramework));

                    var frameworkItems = packageReader.GetFrameworkItems();
                    nearest = frameworkReducer.GetNearest(
                        nuGetFramework,
                        frameworkItems.Select(x => x.TargetFramework));
                }
            }

            // Update csproj file to include the project reference.
            var projectElement = new ProjectElement(project);

            projectElement.AddPackageReference(
                packageId,
                version)
            .Save();
        }