/// <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 System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            try
            {
                NLogService.Setup($"{nameof(VSMonoDebuggerPackage)}.log");
                DebugEngineInstallService.TryRegisterAssembly();

                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                UserSettingsManager.Initialize(this);
                VSMonoDebuggerCommands.Initialize(this);
            }
            catch (UnauthorizedAccessException uex)
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var package = this as Package;
                VsShellUtilities.ShowMessageBox(
                    package,
                    "Failed finish installation of VSMonoDebugger - Please run Visual Studio once as Administrator...",
                    $"{nameof(VSMonoDebuggerPackage)} - Register mono debug engine",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                NLogService.Logger.Error(uex);
            }
            catch (Exception ex)
            {
                NLogService.Logger.Error(ex);
            }

            await base.InitializeAsync(cancellationToken, progress);
        }
        /// <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 void Initialize()
        {
            base.Initialize();

            try
            {
                NLogService.Setup($"{nameof(VSMonoDebuggerPackage)}.log");
                UserSettingsManager.Initialize(this);

                DebugEngineInstallService.TryRegisterAssembly();

                VSMonoDebuggerCommands.Initialize(this);
            }
            catch (UnauthorizedAccessException uex)
            {
                VsShellUtilities.ShowMessageBox(
                    this,
                    "Failed finish installation of VSMonoDebugger - Please run Visual Studio once as Administrator...",
                    $"{nameof(VSMonoDebuggerPackage)} - Register mono debug engine",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                NLogService.Logger.Error(uex);
            }
            catch (Exception ex)
            {
                NLogService.Logger.Error(ex);
            }
        }
        /// <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>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            NLogService.Setup($"{nameof(LocalMonoDebuggerPackage)}.log");
            DebugEngineInstallService.TryRegisterAssembly();

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            OptionsManager.Initialize(this);

            monoExt  = new MonoVSExtension(this, dte);
            commands = new Commands(this, menuCommandService, monoExt);
        }
Пример #4
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 System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            try
            {
                NLogService.Setup($"{nameof(VSMonoDebuggerPackage)}.log");
                DebugEngineInstallService.TryRegisterAssembly();

                // see https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/AsyncPackageMigration
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

                var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

                // TODO replace by services
                UserSettingsManager.Initialize(this);
                _monoVisualStudioExtension = new MonoVisualStudioExtension(this, dte);
                _monoDebuggerCommands      = new VSMonoDebuggerCommands(this, menuCommandService, _monoVisualStudioExtension);

                await AttachToEngineCommand.InitializeAsync(this, menuCommandService, _monoVisualStudioExtension);
            }
            catch (UnauthorizedAccessException uex)
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var package = this as Package;
                VsShellUtilities.ShowMessageBox(
                    package,
                    "Failed finish installation of VSMonoDebugger - Please run Visual Studio once as Administrator...",
                    $"{nameof(VSMonoDebuggerPackage)} - Register mono debug engine",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                Logger.Error(uex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            await base.InitializeAsync(cancellationToken, progress);
        }