public IEnumerable <ITaskItem> GetAdditionalItemsToBeCopied() { if (NativeReferences == null) { yield break; } foreach (var nativeRef in NativeReferences .Where(x => Directory.Exists(x.ItemSpec)) .Select(x => x.ItemSpec)) { foreach (var item in GetItemsFromNativeReference(nativeRef)) { yield return(item); } } }
/// <summary> /// Task entry point. /// </summary> /// <returns></returns> public override bool Execute() { // Process each task item. If one of them fails we still process the // rest of them, but remember that the task should return failure. bool retValue = true; int reference = 0; Hashtable containingReferenceFilesTable = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable containedPrerequisiteAssembliesTable = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable containedComComponentsTable = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable containedTypeLibrariesTable = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable containedLooseTlbFilesTable = new Hashtable(StringComparer.OrdinalIgnoreCase); Hashtable containedLooseEtcFilesTable = new Hashtable(StringComparer.OrdinalIgnoreCase); for (reference = 0; reference < NativeReferences.GetLength(0); reference++) { ITaskItem item = NativeReferences[reference]; string path = item.GetMetadata("HintPath"); // If no HintPath then fallback to trying to resolve from the assembly identity... if (String.IsNullOrEmpty(path) || !File.Exists(path)) { AssemblyIdentity ai = AssemblyIdentity.FromAssemblyName(item.ItemSpec); if (ai != null) { Log.LogMessageFromResources(MessageImportance.Low, "ResolveNativeReference.ResolveReference", item.ItemSpec); foreach (string searchPath in AdditionalSearchPaths) { Log.LogMessageFromResources(MessageImportance.Low, "ResolveAssemblyReference.FourSpaceIndent", searchPath); } path = ai.Resolve(AdditionalSearchPaths); } } else { Log.LogMessageFromResources(MessageImportance.Low, "ResolveNativeReference.ResolveReference", item.ItemSpec); Log.LogMessageFromResources(MessageImportance.Low, "ResolveAssemblyReference.FourSpaceIndent", path); } if (!String.IsNullOrEmpty(path)) { #if _DEBUG try { #endif if (!ExtractFromManifest(NativeReferences[reference], path, containingReferenceFilesTable, containedPrerequisiteAssembliesTable, containedComComponentsTable, containedTypeLibrariesTable, containedLooseTlbFilesTable, containedLooseEtcFilesTable)) { retValue = false; } #if _DEBUG } catch (Exception) { Debug.Assert(false, "Unexpected exception in ResolveNativeReference.Execute. " + "Please log a MSBuild bug specifying the steps to reproduce the problem."); throw; } #endif } else { Log.LogWarningWithCodeFromResources("ResolveNativeReference.FailedToResolveReference", item.ItemSpec); } } IComparer itemSpecComparer = new ItemSpecComparerClass(); _containingReferenceFiles = new ITaskItem[containingReferenceFilesTable.Count]; containingReferenceFilesTable.Values.CopyTo(_containingReferenceFiles, 0); Array.Sort(_containingReferenceFiles, itemSpecComparer); _containedPrerequisiteAssemblies = new ITaskItem[containedPrerequisiteAssembliesTable.Count]; containedPrerequisiteAssembliesTable.Values.CopyTo(_containedPrerequisiteAssemblies, 0); Array.Sort(_containedPrerequisiteAssemblies, itemSpecComparer); _containedComComponents = new ITaskItem[containedComComponentsTable.Count]; containedComComponentsTable.Values.CopyTo(_containedComComponents, 0); Array.Sort(_containedComComponents, itemSpecComparer); _containedTypeLibraries = new ITaskItem[containedTypeLibrariesTable.Count]; containedTypeLibrariesTable.Values.CopyTo(_containedTypeLibraries, 0); Array.Sort(_containedTypeLibraries, itemSpecComparer); _containedLooseTlbFiles = new ITaskItem[containedLooseTlbFilesTable.Count]; containedLooseTlbFilesTable.Values.CopyTo(_containedLooseTlbFiles, 0); Array.Sort(_containedLooseTlbFiles, itemSpecComparer); _containedLooseEtcFiles = new ITaskItem[containedLooseEtcFilesTable.Count]; containedLooseEtcFilesTable.Values.CopyTo(_containedLooseEtcFiles, 0); Array.Sort(_containedLooseEtcFiles, itemSpecComparer); return(retValue); }