/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static async Task InitializeAsync(AsyncPackage package, IMenuCommandService inCommandService, MonoVisualStudioExtension monoVisualStudioExtension) { // Switch to the main thread - the call to AddCommand in AttachToEngineCommand's constructor requires // the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); OleMenuCommandService commandService = inCommandService as OleMenuCommandService; Project monoProject = monoVisualStudioExtension.GetStartupProject(); CommandID dynamicItemRootId = new CommandID(new Guid(guidDynamicMenuPackageCmdSet), (int)0x1030); if (monoProject == null || !monoProject.Name.Contains("UnrealEngine")) { return; } Instance = new AttachToEngineCommand(package, commandService); Instance.MonoExtension = monoVisualStudioExtension; }
/// <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); }