protected internal AssemblyReference AddAssemblyFromItem(ITaskItem item) { AssemblyReferenceType managedAssembly; AssemblyReference reference; if (this.IsEmbedInteropEnabledForAssembly(item)) { return(null); } switch (this.GetItemAssemblyType(item)) { case AssemblyType.Managed: managedAssembly = AssemblyReferenceType.ManagedAssembly; break; case AssemblyType.Native: managedAssembly = AssemblyReferenceType.NativeAssembly; break; case AssemblyType.Satellite: managedAssembly = AssemblyReferenceType.ManagedAssembly; break; default: managedAssembly = AssemblyReferenceType.Unspecified; break; } if (this.GetItemDependencyType(item) == DependencyType.Install) { reference = this.manifest.AssemblyReferences.Add(item.ItemSpec); this.SetItemAttributes(item, reference); } else { AssemblyIdentity identity = AssemblyIdentity.FromAssemblyName(item.ItemSpec); if (identity.IsStrongName) { reference = new AssemblyReference { AssemblyIdentity = identity }; } else { reference = new AssemblyReference(item.ItemSpec); } this.manifest.AssemblyReferences.Add(reference); reference.IsPrerequisite = true; } reference.ReferenceType = managedAssembly; if (string.Equals(item.GetMetadata("IsPrimary"), "true", StringComparison.Ordinal)) { reference.IsPrimary = true; } return(reference); }
protected internal AssemblyReference AddAssemblyNameFromItem(ITaskItem item, AssemblyReferenceType referenceType) { AssemblyReference assembly = new AssemblyReference(); assembly.AssemblyIdentity = AssemblyIdentity.FromAssemblyName(item.ItemSpec); assembly.ReferenceType = referenceType; _manifest.AssemblyReferences.Add(assembly); string hintPath = item.GetMetadata("HintPath"); if (!String.IsNullOrEmpty(hintPath)) { assembly.SourcePath = hintPath; } SetItemAttributes(item, assembly); return(assembly); }
protected internal AssemblyReference AddAssemblyNameFromItem(ITaskItem item, AssemblyReferenceType referenceType) { AssemblyReference assembly = new AssemblyReference { AssemblyIdentity = AssemblyIdentity.FromAssemblyName(item.ItemSpec), ReferenceType = referenceType }; this.manifest.AssemblyReferences.Add(assembly); string metadata = item.GetMetadata("HintPath"); if (!string.IsNullOrEmpty(metadata)) { assembly.SourcePath = metadata; } this.SetItemAttributes(item, assembly); return(assembly); }
/// <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); }
protected internal AssemblyReference AddAssemblyFromItem(ITaskItem item) { // if the assembly is a no-pia assembly and embed interop is turned on, then we don't write it to the manifest. if (IsEmbedInteropEnabledForAssembly(item)) { return(null); } AssemblyReferenceType referenceType; AssemblyType assemblyType = GetItemAssemblyType(item); switch (assemblyType) { case AssemblyType.Managed: referenceType = AssemblyReferenceType.ManagedAssembly; break; case AssemblyType.Native: referenceType = AssemblyReferenceType.NativeAssembly; break; case AssemblyType.Satellite: referenceType = AssemblyReferenceType.ManagedAssembly; break; default: referenceType = AssemblyReferenceType.Unspecified; break; } DependencyType dependencyType = GetItemDependencyType(item); AssemblyReference assembly; if (dependencyType == DependencyType.Install) { assembly = _manifest.AssemblyReferences.Add(item.ItemSpec); SetItemAttributes(item, assembly); } else { AssemblyIdentity identity = AssemblyIdentity.FromAssemblyName(item.ItemSpec); // If we interpreted the item as a strong name, then treat it as a Fusion display name... if (identity.IsStrongName) { assembly = new AssemblyReference(); assembly.AssemblyIdentity = identity; } else // otherwise treat it as a file path... { assembly = new AssemblyReference(item.ItemSpec); } _manifest.AssemblyReferences.Add(assembly); assembly.IsPrerequisite = true; } assembly.ReferenceType = referenceType; string isPrimary = item.GetMetadata(ItemMetadataNames.isPrimary); if (string.Equals(isPrimary, "true", StringComparison.Ordinal)) { assembly.IsPrimary = true; } return(assembly); }
public override bool Execute() { bool flag = true; int index = 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 (index = 0; index < this.NativeReferences.GetLength(0); index++) { ITaskItem item = this.NativeReferences[index]; string metadata = item.GetMetadata("HintPath"); if (string.IsNullOrEmpty(metadata) || !File.Exists(metadata)) { AssemblyIdentity identity = AssemblyIdentity.FromAssemblyName(item.ItemSpec); if (identity != null) { base.Log.LogMessageFromResources(MessageImportance.Low, "ResolveNativeReference.ResolveReference", new object[] { item.ItemSpec }); foreach (string str2 in this.AdditionalSearchPaths) { base.Log.LogMessageFromResources(MessageImportance.Low, "ResolveAssemblyReference.FourSpaceIndent", new object[] { str2 }); } metadata = identity.Resolve(this.AdditionalSearchPaths); } } else { base.Log.LogMessageFromResources(MessageImportance.Low, "ResolveNativeReference.ResolveReference", new object[] { item.ItemSpec }); base.Log.LogMessageFromResources(MessageImportance.Low, "ResolveAssemblyReference.FourSpaceIndent", new object[] { metadata }); } if (!string.IsNullOrEmpty(metadata)) { if (!this.ExtractFromManifest(this.NativeReferences[index], metadata, containingReferenceFilesTable, containedPrerequisiteAssembliesTable, containedComComponentsTable, containedTypeLibrariesTable, containedLooseTlbFilesTable, containedLooseEtcFilesTable)) { flag = false; } } else { base.Log.LogWarningWithCodeFromResources("ResolveNativeReference.FailedToResolveReference", new object[] { item.ItemSpec }); } } IComparer comparer = new ItemSpecComparerClass(); this.containingReferenceFiles = new ITaskItem[containingReferenceFilesTable.Count]; containingReferenceFilesTable.Values.CopyTo(this.containingReferenceFiles, 0); Array.Sort(this.containingReferenceFiles, comparer); this.containedPrerequisiteAssemblies = new ITaskItem[containedPrerequisiteAssembliesTable.Count]; containedPrerequisiteAssembliesTable.Values.CopyTo(this.containedPrerequisiteAssemblies, 0); Array.Sort(this.containedPrerequisiteAssemblies, comparer); this.containedComComponents = new ITaskItem[containedComComponentsTable.Count]; containedComComponentsTable.Values.CopyTo(this.containedComComponents, 0); Array.Sort(this.containedComComponents, comparer); this.containedTypeLibraries = new ITaskItem[containedTypeLibrariesTable.Count]; containedTypeLibrariesTable.Values.CopyTo(this.containedTypeLibraries, 0); Array.Sort(this.containedTypeLibraries, comparer); this.containedLooseTlbFiles = new ITaskItem[containedLooseTlbFilesTable.Count]; containedLooseTlbFilesTable.Values.CopyTo(this.containedLooseTlbFiles, 0); Array.Sort(this.containedLooseTlbFiles, comparer); this.containedLooseEtcFiles = new ITaskItem[containedLooseEtcFilesTable.Count]; containedLooseEtcFilesTable.Values.CopyTo(this.containedLooseEtcFiles, 0); Array.Sort(this.containedLooseEtcFiles, comparer); return(flag); }