protected virtual bool ParseReferenceItems(IList <ProjectInfo> referencedProjects) { ICollection <ProjectItemElement> allItems = _project.Items; List <ProjectItemElement> references = new List <ProjectItemElement>(); List <ProjectItemElement> comReferences = new List <ProjectItemElement>(); List <ProjectItemElement> projectReferences = new List <ProjectItemElement>(); foreach (ProjectItemElement item in allItems) { switch (item.ItemType) { case "Reference": references.Add(item); break; case "COMReference": comReferences.Add(item); break; case "ProjectReference": projectReferences.Add(item); break; } } IList <string> referencedAssemblies = this.ReferencedAssemblies; IList <string> referencedKnownAssemblies = this.ReferencedKnownAssemblies; foreach (ProjectItemElement item in references) { string referenceInclude = item.Include; if (referenceInclude.IndexOf(',') > 0) { AssemblyName asmName = new AssemblyName(referenceInclude); referenceInclude = asmName.Name; } string referencedAssembly = referenceInclude + ".dll"; if (ProjectSectionFactory.IsKnownAssemblyName(referencedAssembly)) { referencedKnownAssemblies.Add(referencedAssembly); continue; } if (item.HasMetadata) { ProjectMetadataElement hintMetadata = null; foreach (ProjectMetadataElement metadata in item.Metadata) { if (String.Equals(metadata.Name, "HintPath", StringComparison.OrdinalIgnoreCase)) { hintMetadata = metadata; break; } } if (hintMetadata != null) { string fullPath = Path.GetFullPath( Path.Combine(this.ProjectDir, hintMetadata.Value)); if (File.Exists(fullPath)) { referencedAssemblies.Add(fullPath); } } } else if (!String.IsNullOrEmpty(this.OutputType)) { // Trying some possibilities... string extension = null; switch (this.OutputType.ToLower()) { case "dll": case "library": case "dynamiclibrary": extension = ".dll"; break; case "exe": case "application": extension = ".exe"; break; } if (!String.IsNullOrEmpty(extension)) { // A referenced file in the project directory... string fullPath = Path.GetFullPath(Path.Combine(this.ProjectDir, referenceInclude + extension)); if (!File.Exists(fullPath) && (!String.IsNullOrEmpty(this.OutputPath) && Directory.Exists(this.OutputPath))) { // A referenced file in the output directory... fullPath = Path.GetFullPath(Path.Combine( this.OutputPath, referenceInclude + extension)); } if (!String.IsNullOrEmpty(fullPath) && File.Exists(fullPath)) { referencedAssemblies.Add(fullPath); } } } } foreach (ProjectItemElement item in comReferences) { //string referenceInclude = item.Include; //if (referenceInclude.IndexOf(',') > 0) //{ // AssemblyName asmName = new AssemblyName(referenceInclude); // referenceInclude = asmName.Name; //} //if (item.HasMetadata) //{ // foreach (ProjectMetadataElement metadata in item.Metadata) // { // } //} } foreach (ProjectItemElement item in projectReferences) { string referenceInclude = item.Include; if (String.IsNullOrEmpty(referenceInclude) || !item.HasMetadata) { continue; } string projectName = String.Empty; string projectGuid = String.Empty; foreach (ProjectMetadataElement metadata in item.Metadata) { if (String.Equals(metadata.Name, "Project", StringComparison.OrdinalIgnoreCase)) { projectGuid = metadata.Value; } else if (String.Equals(metadata.Name, "Name", StringComparison.OrdinalIgnoreCase)) { projectName = metadata.Value; } } string projectPath = String.Empty; if (Path.IsPathRooted(referenceInclude)) { projectPath = Path.GetFullPath(referenceInclude); } else { projectPath = Path.GetFullPath( Path.Combine(this.ProjectDir, referenceInclude)); } if (File.Exists(projectPath)) { if (String.IsNullOrEmpty(projectName)) { projectName = Path.GetFileNameWithoutExtension(projectPath); } ProjectInfo projectInfo = new ProjectInfo(projectPath, projectGuid, projectName); if (projectInfo.IsValid) { referencedProjects.Add(projectInfo); } } else { if (!String.IsNullOrEmpty(projectGuid)) { // If the path does not exist, we try looking through // any available list of references... ProjectInfo projectInfo = this.Context.GetProjectInfo( projectGuid); if (projectInfo != null && projectInfo.IsValid) { referencedProjects.Add(projectInfo); } } } } return(true); }
private bool ParseReferenceItems(IList <ProjectInfo> referencedProjects) { bool isSuccessful = true; string projectDir = this.ProjectDir; IList <string> referencedAssemblies = this.ReferencedAssemblies; IList <string> referencedKnownAssemblies = this.ReferencedKnownAssemblies; foreach (VcProjectReferencesElement references in _project.References) { // For the referenced .NET assemblies... foreach (VcProjectAssemblyReferenceElement reference in references.AssemblyReferences) { string assemblyPath = this.EvaluateMacros(reference.RelativePath); if (String.IsNullOrEmpty(assemblyPath)) { // TODO: This property is actually required and will // not be empty or null... continue; } // For a known assembly (.NET Framework assembly)... string assemblyName = Path.GetFileName(assemblyPath); if (ProjectSectionFactory.IsKnownAssemblyName(assemblyName)) { referencedKnownAssemblies.Add(assemblyName); continue; } if (Path.IsPathRooted(assemblyPath)) { assemblyPath = Path.GetFullPath(assemblyPath); } else { assemblyPath = Path.GetFullPath(Path.Combine( projectDir, assemblyPath)); } if (File.Exists(assemblyPath)) { referencedAssemblies.Add(assemblyPath); } } // For the referenced projects... foreach (VcProjectProjectReferenceElement reference in references.ProjectReferences) { string projectGuid = reference.ReferencedProjectIdentifier; if (String.IsNullOrEmpty(projectGuid)) { throw new InvalidDataException( "The project is not well-formed, it has project Guid."); } string projectPath = this.EvaluateMacros(reference.RelativePathToProject); if (!String.IsNullOrEmpty(projectPath)) { if (Path.IsPathRooted(projectPath)) { projectPath = Path.GetFullPath(projectPath); } else { projectPath = Path.GetFullPath(Path.Combine( projectDir, projectPath)); } } if (File.Exists(projectPath)) { string projectName = reference.Name; if (String.IsNullOrEmpty(projectName)) { projectName = Path.GetFileNameWithoutExtension(projectPath); } ProjectInfo projectInfo = new ProjectInfo(projectPath, projectGuid, projectName); if (projectInfo.IsValid) { referencedProjects.Add(projectInfo); } } else { // If the path does not exist, we try looking through // any available list of references... ProjectInfo projectInfo = this.Context.GetProjectInfo( projectGuid); if (projectInfo != null && projectInfo.IsValid) { referencedProjects.Add(projectInfo); } } } foreach (VcProjectActiveXReferenceElement reference in references.ActiveXReferences) { } } return(isSuccessful); }