Ejemplo n.º 1
0
 /// <summary>
 /// Returns the true or false from a CopyLocalState.
 /// </summary>
 /// <param name="state"></param>
 /// <returns></returns>
 internal static bool IsCopyLocal(CopyLocalState state)
 {
     switch (state)
     {
         case CopyLocalState.YesBecauseOfHeuristic:
         case CopyLocalState.YesBecauseReferenceItemHadMetadata:
             return true;
         case CopyLocalState.NoBecauseConflictVictim:
         case CopyLocalState.NoBecauseUnresolved:
         case CopyLocalState.NoBecauseFrameworkFile:
         case CopyLocalState.NoBecausePrerequisite:
         case CopyLocalState.NoBecauseReferenceItemHadMetadata:
         case CopyLocalState.NoBecauseReferenceFoundInGAC:
         case CopyLocalState.NoBecauseEmbedded:
         case CopyLocalState.NoBecauseParentReferencesFoundInGAC:
             return false;
         default:
             throw new InternalErrorException("Unexpected CopyLocal flag.");
             // Used to be:
             //
             //   ErrorUtilities.VerifyThrow(false, "Unexpected CopyLocal flag.");
             //
             // but this popped up constantly when debugging because its call 
             // directly by a property accessor in Reference.
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the true or false from a CopyLocalState.
        /// </summary>
        internal static bool IsCopyLocal(CopyLocalState state)
        {
            switch (state)
            {
            case CopyLocalState.YesBecauseOfHeuristic:
            case CopyLocalState.YesBecauseReferenceItemHadMetadata:
                return(true);

            case CopyLocalState.NoBecauseConflictVictim:
            case CopyLocalState.NoBecauseUnresolved:
            case CopyLocalState.NoBecauseFrameworkFile:
            case CopyLocalState.NoBecausePrerequisite:
            case CopyLocalState.NoBecauseReferenceItemHadMetadata:
            case CopyLocalState.NoBecauseReferenceResolvedFromGAC:
            case CopyLocalState.NoBecauseReferenceFoundInGAC:
            case CopyLocalState.NoBecauseEmbedded:
            case CopyLocalState.NoBecauseParentReferencesFoundInGAC:
                return(false);

            default:
                throw new InternalErrorException("Unexpected CopyLocal flag.");
                // Used to be:
                //
                //   ErrorUtilities.VerifyThrow(false, "Unexpected CopyLocal flag.");
                //
                // but this popped up constantly when debugging because its call
                // directly by a property accessor in Reference.
            }
        }
 internal void MakeDependentAssemblyReference(Reference sourceReference)
 {
     this.copyLocalState      = CopyLocalState.Undecided;
     this.isPrimary           = false;
     this.DependenciesFound   = false;
     this.wantSpecificVersion = true;
     this.AddSourceItems(sourceReference.GetSourceItems());
     this.AddDependee(sourceReference);
 }
 internal void MakePrimaryAssemblyReference(ITaskItem sourceItem, bool wantSpecificVersionValue, string executableExtension)
 {
     this.copyLocalState    = CopyLocalState.Undecided;
     this.isPrimary         = true;
     this.primarySourceItem = sourceItem;
     if ((executableExtension != null) && (executableExtension.Length > 0))
     {
         this.SetExecutableExtension(executableExtension);
     }
     this.wantSpecificVersion = wantSpecificVersionValue;
     this.DependenciesFound   = false;
     this.AddSourceItem(sourceItem);
 }
        internal static bool IsCopyLocal(CopyLocalState state)
        {
            switch (state)
            {
                case CopyLocalState.YesBecauseOfHeuristic:
                case CopyLocalState.YesBecauseReferenceItemHadMetadata:
                    return true;

                case CopyLocalState.NoBecauseFrameworkFile:
                case CopyLocalState.NoBecausePrerequisite:
                case CopyLocalState.NoBecauseReferenceItemHadMetadata:
                case CopyLocalState.NoBecauseReferenceFoundInGAC:
                case CopyLocalState.NoBecauseConflictVictim:
                case CopyLocalState.NoBecauseUnresolved:
                case CopyLocalState.NoBecauseEmbedded:
                case CopyLocalState.NoBecauseParentReferencesFoundInGAC:
                    return false;
            }
            throw new Microsoft.Build.Shared.InternalErrorException("Unexpected CopyLocal flag.");
        }
Ejemplo n.º 6
0
        internal static bool IsCopyLocal(CopyLocalState state)
        {
            switch (state)
            {
            case CopyLocalState.YesBecauseOfHeuristic:
            case CopyLocalState.YesBecauseReferenceItemHadMetadata:
                return(true);

            case CopyLocalState.NoBecauseFrameworkFile:
            case CopyLocalState.NoBecausePrerequisite:
            case CopyLocalState.NoBecauseReferenceItemHadMetadata:
            case CopyLocalState.NoBecauseReferenceFoundInGAC:
            case CopyLocalState.NoBecauseConflictVictim:
            case CopyLocalState.NoBecauseUnresolved:
            case CopyLocalState.NoBecauseEmbedded:
            case CopyLocalState.NoBecauseParentReferencesFoundInGAC:
                return(false);
            }
            throw new Microsoft.Build.Shared.InternalErrorException("Unexpected CopyLocal flag.");
        }
 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;
             }
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Figure out the what the CopyLocal state of given assembly should be.
        /// </summary>
        /// <param name="assemblyName">The name of the assembly.</param>
        /// <param name="frameworkPaths">The framework paths.</param>
        /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64.</param>
        /// <param name="getRuntimeVersion">Delegate to get runtime version.</param>
        /// <param name="targetedRuntimeVersion">The targeted runtime version.</param>
        /// <param name="fileExists">Delegate to check if a file exists.</param>
        /// <param name="getAssemblyPathInGac">Delegate to get the path to an assembly in the system GAC.</param>
        /// <param name="copyLocalDependenciesWhenParentReferenceInGac">if set to true, copy local dependencies when only parent reference in gac.</param>
        /// <param name="doNotCopyLocalIfInGac">If set to true, do not copy local a reference that exists in the GAC (legacy behavior).</param>
        /// <param name="referenceTable">The reference table.</param>
        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)
            {
                _copyLocalState = CopyLocalState.NoBecauseUnresolved;
                return;
            }

            if (EmbedInteropTypes)
            {
                _copyLocalState = CopyLocalState.NoBecauseEmbedded;
                return;
            }

            // If this item was a conflict victim, then it should not be copy-local.
            if (IsConflictVictim)
            {
                _copyLocalState = 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)
                {
                    _copyLocalState = 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 (DictionaryEntry entry in _sourceItems)
                {
                    bool found;
                    bool result = MetadataConversionUtilities.TryConvertItemMetadataToBool
                        (
                            (ITaskItem)entry.Value,
                            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)
                {
                    _copyLocalState = CopyLocalState.NoBecauseReferenceItemHadMetadata;
                    return;
                }
            }

            // If the item was determined to be an prereq assembly.
            if (IsPrerequisite && !UserRequestedSpecificFile)
            {
                _copyLocalState = CopyLocalState.NoBecausePrerequisite;
                return;
            }

            // Items in the frameworks directory shouldn't be copy-local
            if (IsFrameworkFile(_fullPath, frameworkPaths))
            {
                _copyLocalState = 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 (DictionaryEntry entry in _sourceItems)
                {
                    AssemblyNameExtension primaryAssemblyName = referenceTable.GetReferenceFromItemSpec((string)entry.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)
                {
                    _copyLocalState = 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)
                {
                    _copyLocalState = CopyLocalState.NoBecauseReferenceFoundInGAC;
                    return;
                }
            }

            if (ResolvedFromGac)
            {
                _copyLocalState = CopyLocalState.NoBecauseReferenceResolvedFromGAC;
                return;
            }

            //  It was resolved locally, so copy it.
            _copyLocalState = CopyLocalState.YesBecauseOfHeuristic;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Make this reference a primary assembly reference. 
        /// This is a refrence that is an assembly and is primary.
        /// </summary>
        /// <param name="sourceItem">The source item.</param>
        /// <param name="wantSpecificVersion">Whether the version needs to match exactly or loosely.</param>
        /// <param name="executableExtension">The filename extension that the resulting assembly must have.</param>
        internal void MakePrimaryAssemblyReference
        (
            ITaskItem sourceItem,
            bool wantSpecificVersionValue,
            string executableExtension
        )
        {
            _copyLocalState = CopyLocalState.Undecided;

            // This is a primary reference.
            _isPrimary = true;

            // This is the source item (from the list passed into the task) that
            // originally created this reference.
            _primarySourceItem = sourceItem;
            _sdkName = sourceItem.GetMetadata("SDKName");

            if (executableExtension != null && executableExtension.Length > 0)
            {
                // Set the expected extension.
                SetExecutableExtension(executableExtension);
            }

            // The specific version indicator.
            _wantSpecificVersion = wantSpecificVersionValue;

            // This is an assembly file, so we'll need to find dependencies later.
            DependenciesFound = false;

            // Add source items from the original item.
            AddSourceItem(sourceItem);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Make this reference an assembly that is a dependency of 'sourceReference'
        ///
        /// For example, if 'sourceReference' is MyAssembly.dll then a dependent assembly file
        /// might be en\MyAssembly.resources.dll
        /// 
        /// Assembly references do not have their own dependencies, therefore they are
        /// </summary>
        /// <param name="sourceReference">The source reference that this reference will be dependent on</param>
        internal void MakeDependentAssemblyReference(Reference sourceReference)
        {
            _copyLocalState = CopyLocalState.Undecided;

            // This is a true dependency, so its not primary.
            _isPrimary = false;

            // This is an assembly file, so we'll need to find dependencies later.
            DependenciesFound = false;

            // Dependencies must always be specific version.
            _wantSpecificVersion = true;

            // Add source items from the original item.
            AddSourceItems(sourceReference.GetSourceItems());

            // Add dependees
            AddDependee(sourceReference);
        }
 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;
             }
         }
     }
 }
 internal void MakePrimaryAssemblyReference(ITaskItem sourceItem, bool wantSpecificVersionValue, string executableExtension)
 {
     this.copyLocalState = CopyLocalState.Undecided;
     this.isPrimary = true;
     this.primarySourceItem = sourceItem;
     if ((executableExtension != null) && (executableExtension.Length > 0))
     {
         this.SetExecutableExtension(executableExtension);
     }
     this.wantSpecificVersion = wantSpecificVersionValue;
     this.DependenciesFound = false;
     this.AddSourceItem(sourceItem);
 }
 internal void MakeDependentAssemblyReference(Reference sourceReference)
 {
     this.copyLocalState = CopyLocalState.Undecided;
     this.isPrimary = false;
     this.DependenciesFound = false;
     this.wantSpecificVersion = true;
     this.AddSourceItems(sourceReference.GetSourceItems());
     this.AddDependee(sourceReference);
 }