private void TryBuildSolution() { ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = await _package.GetServiceAsync(typeof(SDTE)) as DTE2; if (dte == null) { ReAttachUtils.ShowError("ReAttach failed", "Unable to rebuild solution before build."); return; } try { dte.Solution.SolutionBuild.Build(true); } catch (Exception) { } }); }
public async Task InitializeAsync(ReAttachPackage package, ReAttachHistory history, CancellationToken cancellationToken) { _package = package; _history = history; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _menu = (await package.GetServiceAsync(typeof(IMenuCommandService))) as IMenuCommandService; if (_menu == null) { ReAttachUtils.ShowStartupError("Unable to obtain reference to menu service."); return; } _options = new ReAttachOptions(package); for (var i = 0; i < ReAttachConstants.ReAttachHistorySize; i++) { var commandId = new CommandID(ReAttachConstants.ReAttachPackageCmdSet, ReAttachConstants.ReAttachCommandId + i); var command = new OleMenuCommand(ReAttachCommandClicked, commandId); _menu.AddCommand(command); if (i > 0) // Hide all items except first one initially. { command.Visible = false; } _commands[i] = command; } var buildToggleCommandId = new CommandID(ReAttachConstants.ReAttachPackageCmdSet, ReAttachConstants.BuildBeforeReAttachCommandId); var buildCommand = new OleMenuCommand(ReAttachToggleBuildClicked, buildToggleCommandId); buildCommand.Visible = true; buildCommand.Checked = _options.BuildBeforeReAttach; _menu.AddCommand(buildCommand); _buildToggleCommand = buildCommand; }