internal SharedServiceState(ISourceRepositoryProvider sourceRepositoryProvider) { SourceRepositoryProvider = sourceRepositoryProvider; SourceRepositoryProvider.PackageSourceProvider.PackageSourcesChanged += PackageSourcesChanged; SolutionManager = new AsyncLazy <IVsSolutionManager>( ServiceLocator.GetInstanceAsync <IVsSolutionManager>, NuGetUIThreadHelper.JoinableTaskFactory); PackageManager = new AsyncLazy <NuGetPackageManager>( async() => { IDeleteOnRestartManager deleteOnRestartManager = await ServiceLocator.GetInstanceAsync <IDeleteOnRestartManager>(); ISettings settings = await ServiceLocator.GetInstanceAsync <ISettings>(); IVsSolutionManager solutionManager = await SolutionManager.GetValueAsync(CancellationToken.None); return(new NuGetPackageManager( SourceRepositoryProvider, settings, solutionManager, deleteOnRestartManager)); }, NuGetUIThreadHelper.JoinableTaskFactory); SourceRepositories = new AsyncLazy <IReadOnlyCollection <SourceRepository> >( GetSourceRepositoriesAsync, NuGetUIThreadHelper.JoinableTaskFactory); }
public async ValueTask <IReadOnlyList <PackageSource> > GetPackageSourcesAsync(CancellationToken cancellationToken) { var packageSources = await ServiceLocator.GetInstanceAsync <ISourceRepositoryProvider>(); Assumes.NotNull(packageSources); return(packageSources.PackageSourceProvider.LoadPackageSources().ToList()); }
public SharedServiceState() { SolutionManager = new AsyncLazy <IVsSolutionManager>( ServiceLocator.GetInstanceAsync <IVsSolutionManager>, NuGetUIThreadHelper.JoinableTaskFactory); SourceRepositoryProvider = new AsyncLazy <ISourceRepositoryProvider>( ServiceLocator.GetInstanceAsync <ISourceRepositoryProvider>, NuGetUIThreadHelper.JoinableTaskFactory); PackageManager = new AsyncLazy <NuGetPackageManager>( async() => { IDeleteOnRestartManager deleteOnRestartManager = await ServiceLocator.GetInstanceAsync <IDeleteOnRestartManager>(); ISettings settings = await ServiceLocator.GetInstanceAsync <ISettings>(); IVsSolutionManager solutionManager = await SolutionManager.GetValueAsync(CancellationToken.None); ISourceRepositoryProvider sourceRepositoryProvider = await SourceRepositoryProvider.GetValueAsync(CancellationToken.None); return(new NuGetPackageManager( sourceRepositoryProvider, settings, solutionManager, deleteOnRestartManager)); }, NuGetUIThreadHelper.JoinableTaskFactory); }
public async ValueTask UninstallPackagesAsync( string projectId, IReadOnlyList <PackageIdentity> packageIdentities, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectId); Assumes.NotNullOrEmpty(packageIdentities); cancellationToken.ThrowIfCancellationRequested(); MSBuildNuGetProject project = await GetMsBuildNuGetProjectAsync(projectId, cancellationToken); IEnumerable <NuGetProjectAction>?actions = packageIdentities .Select(packageIdentity => NuGetProjectAction.CreateUninstallProjectAction(packageIdentity, project)); NuGetPackageManager packageManager = await _state.PackageManager.GetValueAsync(cancellationToken); Assumes.NotNull(packageManager); INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); Assumes.NotNull(projectContext); await packageManager.ExecuteNuGetProjectActionsAsync( project, actions, projectContext, NullSourceCacheContext.Instance, CancellationToken.None); }
private async ValueTask <(bool, NuGetProject?)> TryGetNuGetProjectMatchingProjectIdAsync(string projectId) { var solutionManager = await ServiceLocator.GetInstanceAsync <IVsSolutionManager>(); Assumes.NotNull(solutionManager); NuGetProject project = (await solutionManager.GetNuGetProjectsAsync()) .FirstOrDefault(p => projectId.Equals(p.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId), StringComparison.OrdinalIgnoreCase)); return(project != null, project); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync( string projectId, PackageIdentity packageIdentity, bool removeDependencies, bool forceRemove, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectId); Assumes.NotNull(packageIdentity); Assumes.False(packageIdentity.HasVersion); Assumes.NotNull(_state.SourceCacheContext); Assumes.NotNull(_state.ResolvedActions); Assumes.Null(_state.PackageIdentity); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); (bool success, NuGetProject? project) = await TryGetNuGetProjectMatchingProjectIdAsync(projectId); Assumes.True(success); Assumes.NotNull(project); var projectActions = new List <ProjectAction>(); var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUninstallPackageAsync( project, packageIdentity.Id, uninstallationContext, projectContext, cancellationToken); foreach (NuGetProjectAction action in actions) { var resolvedAction = new ResolvedAction(project, action); var projectAction = new ProjectAction( CreateProjectActionId(), projectId, action.PackageIdentity, action.NuGetProjectActionType, implicitActions: null); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public async ValueTask ExecuteActionsAsync(IReadOnlyList <ProjectAction> actions, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(actions); cancellationToken.ThrowIfCancellationRequested(); await CatchAndRethrowExceptionAsync(async() => { INuGetProjectContext?projectContext = null; try { projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); Assumes.NotNull(projectContext); if (IsDirectInstall(actions)) { NuGetPackageManager.SetDirectInstall(_state.PackageIdentity, projectContext); } var nugetProjectActions = new List <NuGetProjectAction>(); foreach (ProjectAction action in actions) { if (_state.ResolvedActions.TryGetValue(action.Id, out ResolvedAction resolvedAction)) { nugetProjectActions.Add(resolvedAction.Action); } } Assumes.NotNullOrEmpty(nugetProjectActions); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <NuGetProject> projects = nugetProjectActions.Select(action => action.Project); await packageManager.ExecuteNuGetProjectActionsAsync( projects, nugetProjectActions, projectContext, _state.SourceCacheContext, cancellationToken); } finally { if (projectContext != null) { NuGetPackageManager.ClearDirectInstall(projectContext); } } }); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync( IReadOnlyCollection <string> projectIds, PackageIdentity packageIdentity, bool removeDependencies, bool forceRemove, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNull(packageIdentity); Assumes.False(packageIdentity.HasVersion); Assumes.NotNull(_state.SourceCacheContext); Assumes.Null(_state.PackageIdentity); Assumes.True(_state.ResolvedActions.Count == 0); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var projectActions = new List <ProjectAction>(); var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <NuGetProjectAction> projectsWithActions = await packageManager.PreviewProjectsUninstallPackageAsync( projects, packageIdentity.Id, uninstallationContext, projectContext, cancellationToken); foreach (NuGetProjectAction projectWithActions in projectsWithActions) { var resolvedAction = new ResolvedAction(projectWithActions.Project, projectWithActions); var projectAction = new ProjectAction( CreateProjectActionId(), projectWithActions.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId), projectWithActions.PackageIdentity, projectWithActions.NuGetProjectActionType, implicitActions: null); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public async ValueTask <NuGetPackageManager> GetPackageManagerAsync(CancellationToken cancellationToken) { IDeleteOnRestartManager deleteOnRestartManager = await ServiceLocator.GetInstanceAsync <IDeleteOnRestartManager>(); ISettings settings = await ServiceLocator.GetInstanceAsync <ISettings>(); IVsSolutionManager solutionManager = await SolutionManager.GetValueAsync(cancellationToken); return(new NuGetPackageManager( SourceRepositoryProvider, settings, solutionManager, deleteOnRestartManager)); }
public async ValueTask SavePackageSourcesAsync(IReadOnlyList <PackageSource> sources, PackageSourceUpdateOptions packageSourceUpdateOptions, CancellationToken cancellationToken) { var packageSources = await ServiceLocator.GetInstanceAsync <ISourceRepositoryProvider>(); Assumes.NotNull(packageSources); var packageSources2 = packageSources.PackageSourceProvider as IPackageSourceProvider2; if (packageSources2 != null) { packageSources2.SavePackageSources(sources, packageSourceUpdateOptions); } else { packageSources.PackageSourceProvider.SavePackageSources(sources); } }
public async ValueTask SavePackageSourcesAsync(IReadOnlyList <PackageSource> sources, PackageSourceUpdateOptions packageSourceUpdateOptions, CancellationToken cancellationToken) #pragma warning restore CS0618 // Type or member is obsolete { var packageSources = await ServiceLocator.GetInstanceAsync <ISourceRepositoryProvider>(); Assumes.NotNull(packageSources); #pragma warning disable CS0618 // Type or member is obsolete var packageSources2 = packageSources.PackageSourceProvider as IPackageSourceProvider2; #pragma warning restore CS0618 // Type or member is obsolete if (packageSources2 != null) { packageSources2.SavePackageSources(sources, packageSourceUpdateOptions); } else { packageSources.PackageSourceProvider.SavePackageSources(sources); } }
public async ValueTask InstallPackagesAsync( string projectId, IReadOnlyList <PackageIdentity> packageIdentities, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectId); Assumes.NotNullOrEmpty(packageIdentities); cancellationToken.ThrowIfCancellationRequested(); NuGetProject?project = await SolutionUtility.GetNuGetProjectAsync( _state.SolutionManager, projectId, cancellationToken); Assumes.NotNull(project); SourceRepository?sourceRepository = await GetSourceRepositoryAsync(cancellationToken); IEnumerable <NuGetProjectAction>?actions = packageIdentities .Select(packageIdentity => NuGetProjectAction.CreateInstallProjectAction(packageIdentity, sourceRepository, project)); NuGetPackageManager packageManager = await _state.PackageManager.GetValueAsync(cancellationToken); Assumes.NotNull(packageManager); INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); Assumes.NotNull(projectContext); await packageManager.ExecuteBuildIntegratedProjectActionsAsync( project as BuildIntegratedNuGetProject, actions, projectContext, cancellationToken); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUpdateActionsAsync( IReadOnlyCollection <string> projectIds, IReadOnlyCollection <PackageIdentity> packageIdentities, VersionConstraints versionConstraints, bool includePrelease, DependencyBehavior dependencyBehavior, IReadOnlyList <string> packageSourceNames, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNullOrEmpty(packageIdentities); Assumes.NotNullOrEmpty(packageSourceNames); Assumes.NotNull(_state.SourceCacheContext); Assumes.NotNull(_state.ResolvedActions); Assumes.Null(_state.PackageIdentity); return(await CatchAndRethrowExceptionAsync(async() => { var primarySources = new List <SourceRepository>(); var secondarySources = new List <SourceRepository>(); ISourceRepositoryProvider sourceRepositoryProvider = await _sharedState.SourceRepositoryProvider.GetValueAsync(cancellationToken); IEnumerable <SourceRepository> sourceRepositories = sourceRepositoryProvider.GetRepositories(); var packageSourceNamesSet = new HashSet <string>(packageSourceNames, StringComparer.OrdinalIgnoreCase); foreach (SourceRepository sourceRepository in sourceRepositories) { if (packageSourceNamesSet.Contains(sourceRepository.PackageSource.Name)) { primarySources.Add(sourceRepository); } if (sourceRepository.PackageSource.IsEnabled) { secondarySources.Add(sourceRepository); } } INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var resolutionContext = new ResolutionContext( dependencyBehavior, includePrelease, includeUnlisted: true, versionConstraints, new GatherCache(), _state.SourceCacheContext); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUpdatePackagesAsync( packageIdentities.ToList(), projects, resolutionContext, projectContext, primarySources, secondarySources, cancellationToken); var projectActions = new List <ProjectAction>(); foreach (NuGetProjectAction action in actions) { string projectId = action.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId); var resolvedAction = new ResolvedAction(action.Project, action); var projectAction = new ProjectAction( CreateProjectActionId(), projectId, action.PackageIdentity, action.NuGetProjectActionType, implicitActions: null); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetInstallActionsAsync( IReadOnlyCollection <string> projectIds, PackageIdentity packageIdentity, VersionConstraints versionConstraints, bool includePrelease, DependencyBehavior dependencyBehavior, IReadOnlyList <string> packageSourceNames, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNull(packageIdentity); Assumes.NotNullOrEmpty(packageSourceNames); Assumes.Null(_state.PackageIdentity); Assumes.True(_state.ResolvedActions.Count == 0); Assumes.NotNull(_state.SourceCacheContext); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { _state.PackageIdentity = packageIdentity; IReadOnlyList <SourceRepository> sourceRepositories = await GetSourceRepositoriesAsync( packageSourceNames, cancellationToken); Assumes.NotNullOrEmpty(sourceRepositories); INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var resolutionContext = new ResolutionContext( dependencyBehavior, includePrelease, includeUnlisted: false, versionConstraints, new GatherCache(), _state.SourceCacheContext); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <ResolvedAction> resolvedActions = await packageManager.PreviewProjectsInstallPackageAsync( projects, _state.PackageIdentity, resolutionContext, projectContext, sourceRepositories, cancellationToken); var projectActions = new List <ProjectAction>(); foreach (ResolvedAction resolvedAction in resolvedActions) { List <ImplicitProjectAction>?implicitActions = null; if (resolvedAction.Action is BuildIntegratedProjectAction buildIntegratedAction) { implicitActions = new List <ImplicitProjectAction>(); foreach (NuGetProjectAction?buildAction in buildIntegratedAction.GetProjectActions()) { var implicitAction = new ImplicitProjectAction( CreateProjectActionId(), buildAction.PackageIdentity, buildAction.NuGetProjectActionType); implicitActions.Add(implicitAction); } } string projectId = resolvedAction.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId); var projectAction = new ProjectAction( CreateProjectActionId(), projectId, resolvedAction.Action.PackageIdentity, resolvedAction.Action.NuGetProjectActionType, implicitActions); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public static async ValueTask <SharedServiceState> CreateAsync(CancellationToken cancellationToken) { var sourceRepositoryProvider = await ServiceLocator.GetInstanceAsync <ISourceRepositoryProvider>(); return(new SharedServiceState(sourceRepositoryProvider)); }
public InteractiveLoginProvider() { _dte = new AsyncLazy <DTE>(() => ServiceLocator.GetInstanceAsync <DTE>(), NuGetUIThreadHelper.JoinableTaskFactory); }