private ErgonProjectItem FindReferenceItem(AssemblyIdentity identity, string filePath) { var references = _loadedProject.GetItems(ItemNames.Reference); ErgonProjectItem item = null; var fileName = Path.GetFileNameWithoutExtension(filePath); if (identity != null) { var shortAssemblyName = identity.Name; var fullAssemblyName = identity.GetDisplayName(); // check for short name match item = references.FirstOrDefault(it => string.Compare(it.EvaluatedInclude, shortAssemblyName, StringComparison.OrdinalIgnoreCase) == 0); // check for full name match if (item == null) { item = references.FirstOrDefault(it => string.Compare(it.EvaluatedInclude, fullAssemblyName, StringComparison.OrdinalIgnoreCase) == 0); } } // check for file path match if (item == null) { var relativePath = PathUtilities.GetRelativePath(_loadedProject.DirectoryPath, filePath); item = references.FirstOrDefault(it => PathUtilities.PathsEqual(it.EvaluatedInclude, filePath) || PathUtilities.PathsEqual(it.EvaluatedInclude, relativePath) || PathUtilities.PathsEqual(GetHintPath(it), filePath) || PathUtilities.PathsEqual(GetHintPath(it), relativePath)); } // check for partial name match if (item == null && identity != null) { var partialName = identity.Name + ","; var items = references.Where(it => it.EvaluatedInclude.StartsWith(partialName, StringComparison.OrdinalIgnoreCase)).ToList(); if (items.Count == 1) { item = items[0]; } } return(item); }
private ErgonProjectItem FindProjectReferenceItem(string projectName, string projectFilePath) { var references = _loadedProject.GetItems(ItemNames.ProjectReference); var relativePath = PathUtilities.GetRelativePath(_loadedProject.DirectoryPath, projectFilePath); ErgonProjectItem item = null; // find by project file path item = references.First(it => PathUtilities.PathsEqual(it.EvaluatedInclude, relativePath) || PathUtilities.PathsEqual(it.EvaluatedInclude, projectFilePath)); // try to find by project name if (item == null) { item = references.First(it => string.Compare(projectName, it.GetMetadataValue(MetadataNames.Name), StringComparison.OrdinalIgnoreCase) == 0); } return(item); }
private static string GetHintPath(ErgonProjectItem item) => item.Metadata.FirstOrDefault(m => string.Equals(m.Key, MetadataNames.HintPath, StringComparison.OrdinalIgnoreCase)).Value ?? string.Empty;