Ejemplo n.º 1
0
        private async Task InitializeAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            _vsSolution = await _asyncVSSolution.GetValueAsync();

            var dte = await _dte.GetValueAsync();

            UserAgent.SetUserAgentString(
                new UserAgentStringBuilder(VSNuGetClientName).WithVisualStudioSKU(dte.GetFullVsVersionString()));

            HttpHandlerResourceV3.CredentialService = new Lazy <ICredentialService>(() =>
            {
                return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
                {
                    return await _credentialServiceProvider.GetCredentialServiceAsync();
                }));
            });

            _vsMonitorSelection = await _asyncServiceProvider.GetServiceAsync <SVsShellMonitorSelection, IVsMonitorSelection>();

            var solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid;

            _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie);

            var hr = _vsMonitorSelection.AdviseSelectionEvents(this, out _selectionEventsCookie);

            ErrorHandler.ThrowOnFailure(hr);
            hr = _vsSolution.AdviseSolutionEvents(this, out _solutionEventsCookie);
            ErrorHandler.ThrowOnFailure(hr);

            // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events.
            _solutionEvents = dte.Events.SolutionEvents;
            _solutionEvents.BeforeClosing  += OnBeforeClosing;
            _solutionEvents.AfterClosing   += OnAfterClosing;
            _solutionEvents.ProjectAdded   += OnEnvDTEProjectAdded;
            _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved;
            _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed;

            var vSStd97CmdIDGUID = VSConstants.GUID_VSStandardCommandSet97.ToString("B");
            var solutionSaveID   = (int)VSConstants.VSStd97CmdID.SaveSolution;
            var solutionSaveAsID = (int)VSConstants.VSStd97CmdID.SaveSolutionAs;

            _solutionSaveEvent   = dte.Events.get_CommandEvents(vSStd97CmdIDGUID, solutionSaveID);
            _solutionSaveAsEvent = dte.Events.get_CommandEvents(vSStd97CmdIDGUID, solutionSaveAsID);

            _solutionSaveEvent.BeforeExecute   += SolutionSaveAs_BeforeExecute;
            _solutionSaveEvent.AfterExecute    += SolutionSaveAs_AfterExecute;
            _solutionSaveAsEvent.BeforeExecute += SolutionSaveAs_BeforeExecute;
            _solutionSaveAsEvent.AfterExecute  += SolutionSaveAs_AfterExecute;

            _projectSystemCache.CacheUpdated += NuGetCacheUpdate_After;
        }
Ejemplo n.º 2
0
        private async Task <IVsPathContext> TryCreateUserWideContextAsync()
        {
            // It's acceptable to cache these results cause currently:
            // 1. We do not reload configs
            // 2. There is no way to edit gpf/fallback folders through the PM UI.
            var settings = await _userWideSettings.GetValueAsync();

            var outputPathContext = new VsPathContext(NuGetPathContext.Create(settings), _telemetryProvider);

            return(outputPathContext);
        }