internal void SetFinalCopyLocalState ( AssemblyNameExtension assemblyName, string[] frameworkPaths, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, FileExists fileExists, GetAssemblyPathInGac getAssemblyPathInGac, bool copyLocalDependenciesWhenParentReferenceInGac, bool doNotCopyLocalIfInGac, ReferenceTable referenceTable ) { // If this item was unresolvable, then copy-local is false. if (IsUnresolvable) { CopyLocal = CopyLocalState.NoBecauseUnresolved; return; } if (EmbedInteropTypes) { CopyLocal = CopyLocalState.NoBecauseEmbedded; return; } // If this item was a conflict victim, then it should not be copy-local. if (IsConflictVictim) { CopyLocal = CopyLocalState.NoBecauseConflictVictim; return; } // If this is a primary reference then see if there's a Private metadata on the source item if (IsPrimary) { bool found; bool result = MetadataConversionUtilities.TryConvertItemMetadataToBool ( PrimarySourceItem, ItemMetadataNames.privateMetadata, out found ); if (found) { CopyLocal = result ? CopyLocalState.YesBecauseReferenceItemHadMetadata : CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } else { // This is a dependency. If any primary reference that lead to this dependency // has Private=false, then this dependency should false too. bool privateTrueFound = false; bool privateFalseFound = false; foreach (ITaskItem item in _sourceItems.Values) { bool found; bool result = MetadataConversionUtilities.TryConvertItemMetadataToBool ( item, ItemMetadataNames.privateMetadata, out found ); if (found) { if (result) { privateTrueFound = true; // Once we hit this once we know there will be no modification to CopyLocal state. // so we can immediately... break; } else { privateFalseFound = true; } } } if (privateFalseFound && !privateTrueFound) { CopyLocal = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } // If the item was determined to be an prereq assembly. if (IsPrerequisite && !UserRequestedSpecificFile) { CopyLocal = CopyLocalState.NoBecausePrerequisite; return; } // Items in the frameworks directory shouldn't be copy-local if (IsFrameworkFile(_fullPath, frameworkPaths)) { CopyLocal = CopyLocalState.NoBecauseFrameworkFile; return; } // We are a dependency, check to see if all of our parent references have come from the GAC if (!IsPrimary && !copyLocalDependenciesWhenParentReferenceInGac) { // Did we discover a parent reference which was not found in the GAC bool foundSourceItemNotInGac = false; // Go through all of the parent source items and check to see if they were found in the GAC foreach (string key in _sourceItems.Keys) { AssemblyNameExtension primaryAssemblyName = referenceTable.GetReferenceFromItemSpec(key); Reference primaryReference = referenceTable.GetReference(primaryAssemblyName); if (doNotCopyLocalIfInGac) { // Legacy behavior, don't copy local if the assembly is in the GAC at all if (!primaryReference.FoundInGac.HasValue) { primaryReference.FoundInGac = !string.IsNullOrEmpty(getAssemblyPathInGac(primaryAssemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists, true, false)); } if (!primaryReference.FoundInGac.Value) { foundSourceItemNotInGac = true; break; } } else { if (!primaryReference.ResolvedFromGac) { foundSourceItemNotInGac = true; break; } } } // All parent source items were found in the GAC. if (!foundSourceItemNotInGac) { CopyLocal = CopyLocalState.NoBecauseParentReferencesFoundInGAC; return; } } if (doNotCopyLocalIfInGac) { // Legacy behavior, don't copy local if the assembly is in the GAC at all if (!FoundInGac.HasValue) { FoundInGac = !string.IsNullOrEmpty(getAssemblyPathInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists, true, false)); } if (FoundInGac.Value) { CopyLocal = CopyLocalState.NoBecauseReferenceFoundInGAC; return; } } if (ResolvedFromGac) { CopyLocal = CopyLocalState.NoBecauseReferenceResolvedFromGAC; return; } // It was resolved locally, so copy it. CopyLocal = CopyLocalState.YesBecauseOfHeuristic; }
internal void SetFinalCopyLocalState(AssemblyNameExtension assemblyName, string[] frameworkPaths, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, Microsoft.Build.Shared.FileExists fileExists, bool copyLocalDependenciesWhenParentReferenceInGac, ReferenceTable referenceTable, CheckIfAssemblyInGac checkIfAssemblyInGac) { if (this.IsUnresolvable) { this.copyLocalState = CopyLocalState.NoBecauseUnresolved; } else if (this.EmbedInteropTypes) { this.copyLocalState = CopyLocalState.NoBecauseEmbedded; } else if (this.IsConflictVictim) { this.copyLocalState = CopyLocalState.NoBecauseConflictVictim; } else { if (this.IsPrimary) { bool flag; bool flag2 = MetadataConversionUtilities.TryConvertItemMetadataToBool(this.PrimarySourceItem, "Private", out flag); if (flag) { if (flag2) { this.copyLocalState = CopyLocalState.YesBecauseReferenceItemHadMetadata; return; } this.copyLocalState = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } else { bool flag3 = false; bool flag4 = false; foreach (DictionaryEntry entry in this.sourceItems) { bool flag5; bool flag6 = MetadataConversionUtilities.TryConvertItemMetadataToBool((ITaskItem)entry.Value, "Private", out flag5); if (flag5) { if (flag6) { flag3 = true; break; } flag4 = true; } } if (flag4 && !flag3) { this.copyLocalState = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } if (this.IsPrerequisite && !this.UserRequestedSpecificFile) { this.copyLocalState = CopyLocalState.NoBecausePrerequisite; } else if (IsFrameworkFile(this.fullPath, frameworkPaths)) { this.copyLocalState = CopyLocalState.NoBecauseFrameworkFile; } else { if (!this.FoundInGac.HasValue) { bool flag7 = checkIfAssemblyInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists); this.FoundInGac = new bool?(flag7); } if (this.FoundInGac.Value) { this.copyLocalState = CopyLocalState.NoBecauseReferenceFoundInGAC; } else { if (!this.IsPrimary && !copyLocalDependenciesWhenParentReferenceInGac) { bool flag8 = false; foreach (DictionaryEntry entry2 in this.sourceItems) { AssemblyNameExtension referenceFromItemSpec = referenceTable.GetReferenceFromItemSpec((string)entry2.Key); Reference reference = referenceTable.GetReference(referenceFromItemSpec); bool flag9 = false; if (!reference.FoundInGac.HasValue) { flag9 = checkIfAssemblyInGac(referenceFromItemSpec, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists); reference.FoundInGac = new bool?(flag9); } else { flag9 = reference.FoundInGac.Value; } if (!flag9) { flag8 = true; break; } } if (!flag8) { this.copyLocalState = CopyLocalState.NoBecauseParentReferencesFoundInGAC; return; } } this.copyLocalState = CopyLocalState.YesBecauseOfHeuristic; } } } }