protected bool TryGetValidProject(out Project project, out ProjectScriptInfo projectInfo) { var dte2 = (EnvDTE80.DTE2)Package.DTE; project = ((IEnumerable)dte2.ToolWindows.SolutionExplorer.SelectedItems) .OfType <UIHierarchyItem>() .Select(item => item.Object) .OfType <Project>() .FirstOrDefault(); if (project == null) { projectInfo = null; return(false); } projectInfo = ProjectScriptInfo.Load(project.FullName, project.Name); return(projectInfo.IsValid); }