private string GetSelectedFilePath(EnvDTE.DTE dte) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.SelectedItems selectedItems = dte.SelectedItems; if (!(selectedItems?.Count > 0)) { return(null); } var item = selectedItems.Item(1); if (item.Project != null) { return(item.Project.FileName); } else if (item.ProjectItem != null) { if (item.ProjectItem.Properties != null) { return((string)item.ProjectItem.Properties.Item("FullPath").Value); } else { return(item.ProjectItem.FileNames[1]); } } else // is Solution { return(dte.Solution.FileName); } }
internal static EnvDTE.Project GetDTE_SelectedProject(EnvDTE.Solution solution) { EnvDTE.Project project = null; EnvDTE.SelectedItems wSelectedItems = ((EnvDTE.SelectedItems)((EnvDTE.Projects)solution.Projects).DTE.SelectedItems); if (wSelectedItems.Item(1).ProjectItem != null) { project = ((EnvDTE.Project)wSelectedItems.Item(1).ProjectItem.ContainingProject); } if (wSelectedItems.Item(1).Project != null) { project = wSelectedItems.Item(1).Project; } return(project); }