Exemplo n.º 1
0
        /// <summary>
        /// Is the assemblyName in the current redist list and does it have a version number which is higher than what is in the current redist list.
        /// This may happen if someone passes in a p2p reference whcih is a framework assembly which is a higher version than what is in the redist list.
        /// </summary>
        internal bool MarkReferenceForExclusionDueToHigherThanCurrentFramework(AssemblyNameExtension assemblyName, Reference reference)
        {
            bool higherThanCurrentRedistList = false;

            // In this method have we marked a reference as needing to be excluded
            bool haveMarkedReference = false;

            // Mark reference as excluded

            // Check against target framework version if projectTargetFramework is null or less than 4.5, also when flag to force check is set to true
            if (_checkAssemblyVersionAgainstTargetFrameworkVersion)
            {
                // Check assemblies versions when target framework version is less than 4.5

                // Make sure the version is higher than the version in the redist. 
                higherThanCurrentRedistList = (reference.ReferenceVersion != null && reference.ExclusionListLoggingProperties.HighestVersionInRedist != null)
                                              && reference.ReferenceVersion.CompareTo(reference.ExclusionListLoggingProperties.HighestVersionInRedist) > 0;

                if (higherThanCurrentRedistList)
                {
                    LogExclusionReason reason = new LogExclusionReason(LogHigherVersionUnresolve);
                    reference.ExclusionListLoggingProperties.ExclusionReasonLogDelegate = reason;
                    reference.ExclusionListLoggingProperties.IsInExclusionList = true;
                    haveMarkedReference = true;
                }
            }

            return haveMarkedReference;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Does the assembly have a targetFrameworkAttribute which has a higher framework version than what the project is currently targeting.
        /// This may happen for example if a p2p is done between two projects with built against different target frameworks.
        /// </summary>
        internal bool MarkReferenceForExclusionDueToHigherThanCurrentFrameworkAttribute(AssemblyNameExtension assemblyName, Reference reference)
        {
            bool higherThanCurrentFramework = false;
            // In this method have we marked a reference as needing to be excluded
            bool haveMarkedReference = false;

            if (!(reference.IsResolved && _fileExists(reference.FullPath)) || reference.IsPrerequisite || (_frameworkPaths != null && Reference.IsFrameworkFile(reference.FullPath, _frameworkPaths)))
            {
                return false;
            }

            // Make sure the version is higher than the version in the redist. 
            // If the identifier are not equal we do not check since we are not trying to catch cross framework incompatibilities.
            higherThanCurrentFramework = reference.FrameworkNameAttribute != null
                                         && _targetFrameworkMoniker != null
                                         && String.Equals(reference.FrameworkNameAttribute.Identifier, _targetFrameworkMoniker.Identifier, StringComparison.OrdinalIgnoreCase)
                                         && reference.FrameworkNameAttribute.Version > _targetFrameworkMoniker.Version;

            // Mark reference as excluded
            if (higherThanCurrentFramework)
            {
                LogExclusionReason reason = new LogExclusionReason(LogHigherVersionUnresolveDueToAttribute);
                reference.ExclusionListLoggingProperties.ExclusionReasonLogDelegate = reason;
                reference.ExclusionListLoggingProperties.IsInExclusionList = true;
                haveMarkedReference = true;
            }

            return haveMarkedReference;
        }
Exemplo n.º 3
0
        /// <summary>
        /// A primary references has been determined to be in the black list, it needs to be removed from the list of references by not being added to the list of good references
        /// and added to the list of removed references.
        /// </summary>
        private static void RemovePrimaryReferenceMarkedForExclusion(LogExclusionReason logExclusionReason, bool removeOnlyNoWarning, string subsetName, List<Reference> removedReferences, AssemblyNameExtension assemblyName, Reference assemblyReference)
        {
            removedReferences.Add(assemblyReference);

            if (!removeOnlyNoWarning && logExclusionReason != null)
            {
                // Note a primary references will always have a PrimarySourceItem which is not null
                logExclusionReason(true, assemblyName, assemblyReference, assemblyReference.PrimarySourceItem, subsetName);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// If a reference is a higher version than what exists in the redist list of the target framework then 
        /// this reference needs to be marked as excluded so that it is not not allowed to be referenced. 
        /// 
        /// If the user needs this reference then they need to set specific version to true.
        /// </summary>
        internal bool MarkReferencesExcludedDueToOtherFramework(AssemblyNameExtension assemblyName, Reference reference)
        {
            bool haveMarkedReference = false;

            // If the reference was not resolved from the GAC or AssemblyFolders then 
            // we do not need to check it if came from another framework
            string resolvedSearchPath = reference.ResolvedSearchPath;
            bool resolvedFromGAC = resolvedSearchPath.Equals(AssemblyResolutionConstants.gacSentinel, StringComparison.OrdinalIgnoreCase);
            bool resolvedFromAssemblyFolders = resolvedSearchPath.Equals(AssemblyResolutionConstants.assemblyFoldersSentinel, StringComparison.OrdinalIgnoreCase);

            if (!resolvedFromGAC && !resolvedFromAssemblyFolders && reference.IsResolved)
            {
                return false;
            }

            bool inLaterRedistListAndFromGlobalLocation = false;

            // Check against target framework version if projectTargetFramework is null or less than 4.5, also when flag to force check is set to true
            if (_checkAssemblyVersionAgainstTargetFrameworkVersion)
            {
                // Did the assembly name get resolved from a GlobalLocation, GAC or AssemblyFolders and is it in the frameworkList.xml for the 
                // highest version of the currently targeted framework identifier.
                inLaterRedistListAndFromGlobalLocation = InLatestRedistList(assemblyName, reference);

                if (inLaterRedistListAndFromGlobalLocation)
                {
                    LogExclusionReason reason = new LogExclusionReason(LogAnotherFrameworkUnResolve);
                    reference.ExclusionListLoggingProperties.ExclusionReasonLogDelegate = reason;
                    reference.ExclusionListLoggingProperties.IsInExclusionList = true;
                    haveMarkedReference = true;
                }
            }

            return haveMarkedReference;
        }
Exemplo n.º 5
0
        /// <summary>
        /// We have determined the given assembly reference is in the black list, we now need to find the primary references which caused it and make sure those are removed from the list of references.
        /// </summary>
        private void RemoveDependencyMarkedForExclusion(LogExclusionReason logExclusionReason, bool removeOnlyNoWarning, string subsetName, Dictionary<AssemblyNameExtension, Reference> goodReferences, List<Reference> removedReferences, AssemblyNameExtension assemblyName, Reference assemblyReference)
        {
            // For a dependency we would like to remove the primary references which caused this dependency to be found.
            // Source Items is the list of primary itemspecs which lead to the current reference being discovered. 
            ICollection dependees = assemblyReference.GetSourceItems();
            foreach (ITaskItem dependee in dependees)
            {
                string dependeeItemSpec = dependee.ItemSpec;

                if (assemblyReference.IsPrimary)
                {
                    // Dont process yourself
                    if (String.Compare(dependeeItemSpec, assemblyReference.PrimarySourceItem.ItemSpec, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        continue;
                    }
                }

                // Get the primary reference assemblyName
                AssemblyNameExtension primaryAssemblyName = GetReferenceFromItemSpec(dependeeItemSpec);

                if (primaryAssemblyName != null)
                {
                    // Get the specific primary reference which caused this dependency
                    Reference primaryAssemblyReference = _references[primaryAssemblyName];
                    bool hasSpecificVersionMetadata = primaryAssemblyReference.WantSpecificVersion;

                    if (!hasSpecificVersionMetadata)
                    {
                        // If the reference has not been removed we need to remove it and possibly remove it from the good reference list.
                        if (!removedReferences.Contains(primaryAssemblyReference))
                        {
                            removedReferences.Add(primaryAssemblyReference);
                            goodReferences.Remove(primaryAssemblyName);
                        }

                        if (!removeOnlyNoWarning && logExclusionReason != null)
                        {
                            logExclusionReason(false, assemblyName, assemblyReference, dependee, subsetName);
                        }
                    }
                }
            }
        }
 private static void RemovePrimaryReferenceMarkedForExclusion(LogExclusionReason logExclusionReason, bool removeOnlyNoWarning, string subsetName, List<Reference> removedReferences, AssemblyNameExtension assemblyName, Reference assemblyReference)
 {
     removedReferences.Add(assemblyReference);
     if (!removeOnlyNoWarning && (logExclusionReason != null))
     {
         logExclusionReason(true, assemblyName, assemblyReference, assemblyReference.PrimarySourceItem, subsetName);
     }
 }
 private void RemoveDependencyMarkedForExclusion(LogExclusionReason logExclusionReason, bool removeOnlyNoWarning, string subsetName, Dictionary<AssemblyNameExtension, Reference> goodReferences, List<Reference> removedReferences, AssemblyNameExtension assemblyName, Reference assemblyReference)
 {
     foreach (ITaskItem item in assemblyReference.GetSourceItems())
     {
         string itemSpec = item.ItemSpec;
         if (!assemblyReference.IsPrimary || (string.Compare(itemSpec, assemblyReference.PrimarySourceItem.ItemSpec, StringComparison.OrdinalIgnoreCase) != 0))
         {
             AssemblyNameExtension referenceFromItemSpec = this.GetReferenceFromItemSpec(itemSpec);
             if (referenceFromItemSpec != null)
             {
                 Reference reference = this.references[referenceFromItemSpec];
                 if (!reference.WantSpecificVersion)
                 {
                     if (!removedReferences.Contains(reference))
                     {
                         removedReferences.Add(reference);
                         goodReferences.Remove(referenceFromItemSpec);
                     }
                     if (!removeOnlyNoWarning && (logExclusionReason != null))
                     {
                         logExclusionReason(false, assemblyName, assemblyReference, item, subsetName);
                     }
                 }
             }
         }
     }
 }
 internal bool MarkReferencesExcludedDueToOtherFramework(AssemblyNameExtension assemblyName, Reference reference)
 {
     bool flag = false;
     string resolvedSearchPath = reference.ResolvedSearchPath;
     bool flag2 = resolvedSearchPath.Equals("{gac}", StringComparison.OrdinalIgnoreCase);
     bool flag3 = resolvedSearchPath.Equals("{assemblyfolders}", StringComparison.OrdinalIgnoreCase);
     if ((!flag2 && !flag3) && reference.IsResolved)
     {
         return false;
     }
     if (this.InLatestRedistList(assemblyName, reference))
     {
         LogExclusionReason reason = new LogExclusionReason(this.LogAnotherFrameworkUnResolve);
         reference.ExclusionListLoggingProperties.ExclusionReasonLogDelegate = reason;
         reference.ExclusionListLoggingProperties.IsInExclusionList = true;
         flag = true;
     }
     return flag;
 }
 internal bool MarkReferenceForExclusionDueToHigherThanCurrentFramework(AssemblyNameExtension assemblyName, Reference reference)
 {
     bool flag2 = false;
     if (((reference.ReferenceVersion != null) && (reference.ExclusionListLoggingProperties.HighestVersionInRedist != null)) && (reference.ReferenceVersion.CompareTo(reference.ExclusionListLoggingProperties.HighestVersionInRedist) > 0))
     {
         LogExclusionReason reason = new LogExclusionReason(this.LogHigherVersionUnresolve);
         reference.ExclusionListLoggingProperties.ExclusionReasonLogDelegate = reason;
         reference.ExclusionListLoggingProperties.IsInExclusionList = true;
         flag2 = true;
     }
     return flag2;
 }