private static async Task <RestoreResultPair> PreviewAddPackageReference(PackageReferenceArgs packageReferenceArgs, DependencyGraphSpec dgSpec, PackageSpec originalPackageSpec) { // Set user agent and connection settings. XPlatUtility.ConfigureProtocol(); var providerCache = new RestoreCommandProvidersCache(); using (var cacheContext = new SourceCacheContext()) { cacheContext.NoCache = false; cacheContext.IgnoreFailedSources = false; // Pre-loaded request provider containing the graph file var providers = new List <IPreLoadedRestoreRequestProvider>(); // Create a copy to avoid modifying the original spec which may be shared. var updatedPackageSpec = originalPackageSpec.Clone(); PackageSpecOperations.AddOrUpdateDependency(updatedPackageSpec, packageReferenceArgs.PackageDependency); providers.Add(new DependencyGraphSpecRequestProvider(providerCache, dgSpec)); var restoreContext = new RestoreArgs() { CacheContext = cacheContext, LockFileVersion = LockFileFormat.Version, Log = packageReferenceArgs.Logger, MachineWideSettings = new XPlatMachineWideSetting(), GlobalPackagesFolder = packageReferenceArgs.PackageDirectory, PreLoadedRequestProviders = providers, Sources = packageReferenceArgs.Sources?.ToList() }; // Generate Restore Requests. There will always be 1 request here since we are restoring for 1 project. var restoreRequests = await RestoreRunner.GetRequests(restoreContext); // Run restore without commit. This will always return 1 Result pair since we are restoring for 1 request. var restoreResult = await RestoreRunner.RunWithoutCommit(restoreRequests, restoreContext); return(restoreResult.Single()); } }
private static async Task <RestoreResultPair> PreviewAddPackageReferenceAsync(PackageReferenceArgs packageReferenceArgs, DependencyGraphSpec dgSpec) { // Set user agent and connection settings. XPlatUtility.ConfigureProtocol(); var providerCache = new RestoreCommandProvidersCache(); using (var cacheContext = new SourceCacheContext()) { cacheContext.NoCache = false; cacheContext.IgnoreFailedSources = false; // Pre-loaded request provider containing the graph file var providers = new List <IPreLoadedRestoreRequestProvider> { new DependencyGraphSpecRequestProvider(providerCache, dgSpec) }; var restoreContext = new RestoreArgs() { CacheContext = cacheContext, LockFileVersion = LockFileFormat.Version, Log = packageReferenceArgs.Logger, MachineWideSettings = new XPlatMachineWideSetting(), GlobalPackagesFolder = packageReferenceArgs.PackageDirectory, PreLoadedRequestProviders = providers, Sources = packageReferenceArgs.Sources?.ToList() }; // Generate Restore Requests. There will always be 1 request here since we are restoring for 1 project. var restoreRequests = await RestoreRunner.GetRequests(restoreContext); //Setup the Credential Service DefaultCredentialServiceUtility.SetupDefaultCredentialService(restoreContext.Log, !packageReferenceArgs.Interactive); // Run restore without commit. This will always return 1 Result pair since we are restoring for 1 request. var restoreResult = await RestoreRunner.RunWithoutCommit(restoreRequests, restoreContext); return(restoreResult.Single()); } }