示例#1
0
        internal static async ValueTask ProfferServicesAsync(IAsyncServiceProvider serviceProvider)
        {
            Assumes.NotNull(serviceProvider);

            IBrokeredServiceContainer brokeredServiceContainer = await serviceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>();

            var factory = new NuGetBrokeredServiceFactory();

            // This service descriptor reference will cause NuGet.VisualStudio.Contracts.dll to load.
            brokeredServiceContainer.Proffer(ContractsNuGetServices.NuGetProjectServiceV1, factory.CreateNuGetProjectServiceV1);

            // These service descriptor references will cause NuGet.VisualStudio.Internal.Contracts.dll to load.
            brokeredServiceContainer.Proffer(NuGetServices.SourceProviderService, factory.CreateSourceProviderServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.SolutionManagerService, factory.CreateSolutionManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectManagerService, factory.CreateProjectManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectUpgraderService, factory.CreateProjectUpgraderServiceAsync);
        }
示例#2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            await AddMenuCommandHandlersAsync();

            // This instantiates a decoupled ICommand instance responsible to locate and display output pane by a UI control
            UI.Commands.ShowErrorsCommand = new ShowErrorsCommand(this);

            _vsMonitorSelection = new AsyncLazy <IVsMonitorSelection>(
                async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // get the UI context cookie for the debugging mode
                var vsMonitorSelection = await GetServiceAsync(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
                Assumes.Present(vsMonitorSelection);
                // get the solution not building and not debugging cookie
                var guidCmdUI = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;
                vsMonitorSelection.GetCmdUIContextCookie(
                    ref guidCmdUI, out _solutionExistsAndFullyLoadedContextCookie);

                guidCmdUI = VSConstants.UICONTEXT.SolutionExistsAndNotBuildingAndNotDebugging_guid;
                vsMonitorSelection.GetCmdUIContextCookie(
                    ref guidCmdUI, out _solutionNotBuildingAndNotDebuggingContextCookie);

                guidCmdUI = VSConstants.UICONTEXT.SolutionExists_guid;
                vsMonitorSelection.GetCmdUIContextCookie(
                    ref guidCmdUI, out _solutionExistsCookie);

                return(vsMonitorSelection);
            },
                ThreadHelper.JoinableTaskFactory);

            IBrokeredServiceContainer brokeredServiceContainer = await this.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>();

            var lazySolutionManager         = new AsyncLazy <IVsSolutionManager>(() => ServiceLocator.GetInstanceAsync <IVsSolutionManager>(), ThreadHelper.JoinableTaskFactory);
            var lazySettings                = new AsyncLazy <ISettings>(() => ServiceLocator.GetInstanceAsync <ISettings>(), ThreadHelper.JoinableTaskFactory);
            var nuGetBrokeredServiceFactory = new NuGetBrokeredServiceFactory(lazySolutionManager, lazySettings);

            brokeredServiceContainer.Proffer(NuGetServices.NuGetProjectServiceV1, nuGetBrokeredServiceFactory.CreateNuGetProjectServiceV1);
        }
        // This returns a disposable for test purposes only.
        internal static async ValueTask <IDisposable> ProfferServicesAsync(IAsyncServiceProvider serviceProvider)
        {
            Assumes.NotNull(serviceProvider);

            IBrokeredServiceContainer brokeredServiceContainer = await serviceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>();

#pragma warning disable CA2000 // Dispose objects before losing scope
            var factory = new NuGetBrokeredServiceFactory();
#pragma warning restore CA2000 // Dispose objects before losing scope

            // This service descriptor reference will cause NuGet.VisualStudio.Contracts.dll to load.
            brokeredServiceContainer.Proffer(ContractsNuGetServices.NuGetProjectServiceV1, factory.CreateNuGetProjectServiceV1);

            // These service descriptor references will cause NuGet.VisualStudio.Internal.Contracts.dll to load.
            brokeredServiceContainer.Proffer(NuGetServices.SourceProviderService, factory.CreateSourceProviderServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.SolutionManagerService, factory.CreateSolutionManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectManagerService, factory.CreateProjectManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectUpgraderService, factory.CreateProjectUpgraderServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.SearchService, factory.CreatePackageSearchServiceAsync);

            return(factory);
        }