private void OnShowDialog(object sender, EventArgs e) { var application = (DTE)GetService(typeof(SDTE)); if (application.Solution == null || !application.Solution.IsOpen) { MessageBox.Show("Please open a solution first. ", "No solution"); } else { if (application.Solution.IsDirty) // solution must be saved otherwise adding/removing projects will raise errors { MessageBox.Show("Please save your solution first. \n" + "Select the solution in the Solution Explorer and press Ctrl-S. ", "Solution not saved"); } else if (application.Solution.Projects.OfType <Project>().Any(p => p.IsDirty)) { MessageBox.Show("Please save your projects first. \n" + "Select the project in the Solution Explorer and press Ctrl-S. ", "Project not saved"); } else { var window = new MainDialog(application, GetType().Assembly); var helper = new WindowInteropHelper(window); helper.Owner = (IntPtr)application.MainWindow.HWnd; window.ShowModal(); } } }