static ProjectItem FindAppDotXaml(EnvDTE.Project currentProject, EnvDTE.Solution currentSolution) { // First, look for a file named "App.xaml" in the root of the current project: foreach (EnvDTE.ProjectItem projectItem in currentProject.ProjectItems) { string fileName = projectItem.Name; if (fileName.ToLowerInvariant() == "app.xaml") { return(projectItem); } } // If not found, iterate through all the referencing projects in the solution, and look there: foreach (Project project in SolutionProjectsHelper.GetAllProjectsInSolution(currentSolution)) { // Check if the project references the current project: if (SolutionProjectsHelper.DoesProjectAReferenceProjectB(project, currentProject)) { // Find a file named "app.xaml" in the referenced project: foreach (EnvDTE.ProjectItem projectItem in project.ProjectItems) { string fileName = projectItem.Name; if (fileName.ToLowerInvariant() == "app.xaml") { return(projectItem); } } } } return(null); }
static Dictionary <string, EnvDTE.Project> MakeAssemblyNameToProjectDictionary(EnvDTE.Project currentProject) { // This method returns a dictionary that contains all the assembly names and their corresponding projects (among the referenced projects and the project itself): var assemblyNameToProjectDictionary = new Dictionary <string, EnvDTE.Project>(); foreach (EnvDTE.Project proj in SolutionProjectsHelper.GetReferencedProjets(currentProject, includeTheProjectItselfAmondTheResults: true)) { if (proj.Properties != null) // This may be null if the project is still loading. //todo: in that case, should we notify the user, do something else? { EnvDTE.Property property = proj.Properties.Item("AssemblyName"); if (property != null && property.Value != null) { string assemblyName = property.Value.ToString(); assemblyNameToProjectDictionary[assemblyName] = proj; // If an item with the same key exists, it will be replaced, otherwise it will be added. } } } return(assemblyNameToProjectDictionary); }