public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (assemblyName != null)
     {
         string path = GlobalAssemblyCache.GetLocation(assemblyName, base.targetProcessorArchitecture, base.getRuntimeVersion, base.targetedRuntimeVersion, false, base.fileExists, null, null, wantSpecificVersion);
         if (((path != null) && (path.Length > 0)) && base.fileExists(path))
         {
             foundPath = path;
             return true;
         }
         if (assembliesConsideredAndRejected != null)
         {
             ResolutionSearchLocation location = new ResolutionSearchLocation {
                 FileNameAttempted = assemblyName.FullName,
                 SearchPath = base.searchPathElement,
                 AssemblyName = assemblyName,
                 Reason = NoMatchReason.NotInGac
             };
             assembliesConsideredAndRejected.Add(location);
         }
     }
     return false;
 }
 public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (rawFileNameCandidate != null)
     {
         if (base.fileExists(rawFileNameCandidate))
         {
             userRequestedSpecificFile = true;
             foundPath = rawFileNameCandidate;
             return true;
         }
         if (assembliesConsideredAndRejected != null)
         {
             ResolutionSearchLocation location = null;
             location = new ResolutionSearchLocation {
                 FileNameAttempted = rawFileNameCandidate,
                 SearchPath = base.searchPathElement,
                 Reason = NoMatchReason.NotAFileNameOnDisk
             };
             assembliesConsideredAndRejected.Add(location);
         }
     }
     return false;
 }
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,

            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            // Resolve to the given path.
            string resolvedPath = ResolveFromDirectory(assemblyName, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, searchPathElement, assembliesConsideredAndRejected);
            if (resolvedPath != null)
            {
                foundPath = resolvedPath;
                return true;
            }


            return false;
        }
Beispiel #4
0
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,

            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            if (hintPath != null && hintPath.Length > 0)
            {
                if (ResolveAsFile(hintPath, assemblyName, isPrimaryProjectReference, wantSpecificVersion, true, assembliesConsideredAndRejected))
                {
                    userRequestedSpecificFile = true;
                    foundPath = hintPath;
                    return true;
                }
            }

            foundPath = null;
            userRequestedSpecificFile = false;
            return false;
        }
        /// <summary>
        /// Implementation guts for ResolveReference.
        /// </summary>
        /// <param name="jaggedResolvers">The array of resolvers to search with.</param>
        /// <param name="assemblyName">The assembly name to look up.</param>
        /// <param name="rawFileNameCandidate">The file name to match if {RawFileName} is seen. (May be null).</param>
        /// <param name="isPrimaryProjectReference">True if this is a primary reference directly from the project file.</param>
        /// <param name="executableExtensions">The filename extension of the assembly. Must be this or its no match.</param>
        /// <param name="hintPath">This reference's hintpath</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="resolvedSearchPath">Receives the searchPath that the reference was resolved at. Empty if not resolved.</param>
        /// <param name="userRequestedSpecificFile"> This will be true if the user requested a specific file.</param>
        /// <returns>The resolved path</returns>
        internal static string ResolveReference
        (
            IEnumerable<Resolver[]> jaggedResolvers,
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string resolvedSearchPath,
            out bool userRequestedSpecificFile
        )
        {
            // Initialize outs.
            userRequestedSpecificFile = false;
            resolvedSearchPath = String.Empty;

            // Search each group of resolvers
            foreach (Resolver[] resolvers in jaggedResolvers)
            {
                // Tolerate null resolvers.
                if (resolvers == null)
                {
                    break;
                }

                // Search each searchpath.
                foreach (Resolver resolver in resolvers)
                {
                    string fileLocation;
                    if
                    (
                        resolver.Resolve
                        (
                            assemblyName,
                            sdkName,
                            rawFileNameCandidate,
                            isPrimaryProjectReference,
                            wantSpecificVersion,
                            executableExtensions,
                            hintPath,
                            assemblyFolderKey,
                            assembliesConsideredAndRejected,
                            out fileLocation,
                            out userRequestedSpecificFile
                        )
                    )
                    {
                        resolvedSearchPath = resolver.SearchPath;
                        return fileLocation;
                    }
                }
            }

            return null;
        }
 public override bool Execute()
 {
     FrameworkName frameworkmoniker = null;
     FrameworkName name2 = null;
     bool flag = false;
     try
     {
         frameworkmoniker = new FrameworkName(this.TargetFrameworkMoniker);
         flag = !string.IsNullOrEmpty(frameworkmoniker.Profile);
         if (flag)
         {
             name2 = new FrameworkName(frameworkmoniker.Identifier, frameworkmoniker.Version);
         }
         if ((!this.bypassFrameworkInstallChecks && frameworkmoniker.Identifier.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase)) && (frameworkmoniker.Version.Major < 4))
         {
             if (!net35SP1SentinelAssemblyFound.HasValue)
             {
                 AssemblyNameExtension strongName = new AssemblyNameExtension(NET35SP1SentinelAssemblyName);
                 net35SP1SentinelAssemblyFound = new bool?(!string.IsNullOrEmpty(GlobalAssemblyCache.GetLocation(strongName, System.Reflection.ProcessorArchitecture.MSIL, runtimeVersion => "v2.0.50727", new Version("2.0.57027"), false, new Microsoft.Build.Shared.FileExists(Microsoft.Build.Shared.FileUtilities.FileExistsNoThrow), GlobalAssemblyCache.pathFromFusionName, GlobalAssemblyCache.gacEnumerator, false)));
             }
             if (!net35SP1SentinelAssemblyFound.Value)
             {
                 base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NETFX35SP1NotIntstalled", new object[] { this.TargetFrameworkMoniker });
             }
         }
     }
     catch (ArgumentException exception)
     {
         base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.InvalidTargetFrameworkMoniker", new object[] { this.TargetFrameworkMoniker, exception.Message });
         return false;
     }
     try
     {
         this.tfmPaths = this.GetPaths(this.rootPath, frameworkmoniker);
         if ((this.tfmPaths != null) && (this.tfmPaths.Count > 0))
         {
             this.TargetFrameworkMonikerDisplayName = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(this.tfmPaths[0], frameworkmoniker);
         }
         if (flag && (this.tfmPaths != null))
         {
             this.tfmPathsNoProfile = this.GetPaths(this.rootPath, name2);
         }
         if (!flag)
         {
             this.tfmPathsNoProfile = this.tfmPaths;
         }
     }
     catch (Exception exception2)
     {
         base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.ProblemGeneratingReferencePaths", new object[] { this.TargetFrameworkMoniker, exception2.Message });
         if (Microsoft.Build.Shared.ExceptionHandling.IsCriticalException(exception2))
         {
             throw;
         }
         this.tfmPathsNoProfile = null;
         this.TargetFrameworkMonikerDisplayName = null;
     }
     return !base.Log.HasLoggedErrors;
 }
 private static string CheckForFullFusionNameInGac(AssemblyNameExtension assemblyName, string targetProcessorArchitecture, GetPathFromFusionName getPathFromFusionName)
 {
     string fullName = assemblyName.FullName;
     if ((targetProcessorArchitecture != null) && !assemblyName.HasProcessorArchitectureInFusionName)
     {
         fullName = fullName + ", ProcessorArchitecture=" + targetProcessorArchitecture;
     }
     return getPathFromFusionName(fullName);
 }
 private bool CheckForAssemblyInGac(AssemblyNameExtension assemblyName, System.Reflection.ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, Microsoft.Build.Shared.FileExists fileExists)
 {
     string str = null;
     if (assemblyName.Version != null)
     {
         str = GlobalAssemblyCache.GetLocation(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, true, fileExists, null, null, false);
     }
     return (str != null);
 }
 public UnifiedAssemblyName(AssemblyNameExtension preUnified, AssemblyNameExtension postUnified, bool isUnified, UnificationReason unificationReason, bool isPrerequisite, bool? isRedistRoot, string redistName)
 {
     _preUnified = preUnified;
     _postUnified = postUnified;
     _isUnified = isUnified;
     _isPrerequisite = isPrerequisite;
     _isRedistRoot = isRedistRoot;
     _redistName = redistName;
     _unificationReason = unificationReason;
 }
 public UnifiedAssemblyName(AssemblyNameExtension preUnified, AssemblyNameExtension postUnified, bool isUnified, Microsoft.Build.Tasks.UnificationReason unificationReason, bool isPrerequisite, bool? isRedistRoot, string redistName)
 {
     this.preUnified = preUnified;
     this.postUnified = postUnified;
     this.isUnified = isUnified;
     this.isPrerequisite = isPrerequisite;
     this.isRedistRoot = isRedistRoot;
     this.redistName = redistName;
     this.unificationReason = unificationReason;
 }
 internal static string GetLocation(AssemblyNameExtension strongName, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, bool fullFusionName, Microsoft.Build.Shared.FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
 {
     string str = null;
     if (((strongName.GetPublicKeyToken() == null) || (strongName.GetPublicKeyToken().Length == 0)) && (strongName.FullName.IndexOf("PublicKeyToken", StringComparison.OrdinalIgnoreCase) != -1))
     {
         return str;
     }
     getPathFromFusionName = getPathFromFusionName ?? pathFromFusionName;
     getGacEnumerator = getGacEnumerator ?? gacEnumerator;
     if (!strongName.HasProcessorArchitectureInFusionName)
     {
         if ((targetProcessorArchitecture != ProcessorArchitecture.MSIL) && (targetProcessorArchitecture != ProcessorArchitecture.None))
         {
             string str2 = ResolveAssemblyReference.ProcessorArchitectureToString(targetProcessorArchitecture);
             if (fullFusionName)
             {
                 str = CheckForFullFusionNameInGac(strongName, str2, getPathFromFusionName);
             }
             else
             {
                 str = GetLocationImpl(strongName, str2, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
             }
             if ((str != null) && (str.Length > 0))
             {
                 return str;
             }
         }
         if (fullFusionName)
         {
             str = CheckForFullFusionNameInGac(strongName, "MSIL", getPathFromFusionName);
         }
         else
         {
             str = GetLocationImpl(strongName, "MSIL", getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
         }
         if ((str != null) && (str.Length > 0))
         {
             return str;
         }
     }
     if (fullFusionName)
     {
         str = CheckForFullFusionNameInGac(strongName, null, getPathFromFusionName);
     }
     else
     {
         str = GetLocationImpl(strongName, null, getRuntimeVersion, targetedRuntimeVersion, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
     }
     if ((str != null) && (str.Length > 0))
     {
         return str;
     }
     return null;
 }
 private void GetAssemblyMetadata(string path, out AssemblyNameExtension[] dependencies, out string[] scatterFiles)
 {
     FileState fileState = this.GetFileState(path);
     if (fileState.dependencies == null)
     {
         this.getAssemblyMetadata(path, out fileState.dependencies, out fileState.scatterFiles);
         this.isDirty = true;
     }
     dependencies = fileState.dependencies;
     scatterFiles = fileState.scatterFiles;
 }
 internal AssemblyEntry FindHighestVersionInRedistList(AssemblyNameExtension assemblyName)
 {
     foreach (AssemblyEntry entry in this.redistList.FindAssemblyNameFromSimpleName(assemblyName.Name))
     {
         if (entry.AssemblyNameExtension.EqualsIgnoreVersion(assemblyName))
         {
             return entry;
         }
     }
     return null;
 }
 private static void AddToDependencyGraph(Dictionary<Reference, List<ReferenceAssemblyExtensionPair>> dependencyGraph, AssemblyNameExtension assemblyName, Reference assemblyReference)
 {
     foreach (Reference reference in assemblyReference.GetDependees())
     {
         List<ReferenceAssemblyExtensionPair> list = null;
         if (!dependencyGraph.TryGetValue(reference, out list))
         {
             list = new List<ReferenceAssemblyExtensionPair>();
             dependencyGraph.Add(reference, list);
         }
         list.Add(new ReferenceAssemblyExtensionPair(assemblyReference, assemblyName));
     }
 }
        /// <summary>
        /// Do a partial comparison between two assembly name extensions.
        /// Compare the fields of A and B on the following conditions:
        /// 1) A.Field has a non null value
        /// 2) The field has been selected in the comparison flags or the default comparison flags are passed in.
        ///
        /// If A.Field is null then we will not compare A.Field and B.Field even when the comparison flag is set for that field unless skipNullFields is false.
        /// </summary>
        internal bool PartialNameCompare(AssemblyNameExtension that, PartialComparisonFlags comparisonFlags, bool considerRetargetableFlag)
        {
            // Pointer compare.
            if (Object.ReferenceEquals(this, that))
            {
                return(true);
            }

            // If that is null then this and that are not equal. Also, this would cause a crash on the next line.
            if (Object.ReferenceEquals(that, null))
            {
                return(false);
            }

            // Do both have assembly names?
            if (_asAssemblyName != null && that._asAssemblyName != null)
            {
                // Pointer compare.
                if (Object.ReferenceEquals(_asAssemblyName, that._asAssemblyName))
                {
                    return(true);
                }
            }

            // Do the names match?
            if ((comparisonFlags & PartialComparisonFlags.SimpleName) != 0 && Name != null && !String.Equals(Name, that.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if ((comparisonFlags & PartialComparisonFlags.Version) != 0 && Version != null && this.Version != that.Version)
            {
                return(false);
            }

            if ((comparisonFlags & PartialComparisonFlags.Culture) != 0 && CultureInfo != null && (that.CultureInfo == null || !CompareCulture(that)))
            {
                return(false);
            }

            if ((comparisonFlags & PartialComparisonFlags.PublicKeyToken) != 0 && GetPublicKeyToken() != null && !ComparePublicKeyToken(that))
            {
                return(false);
            }

            if (considerRetargetableFlag && (Retargetable != that.Retargetable))
            {
                return(false);
            }
            return(true);
        }
Beispiel #16
0
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="sdkName">The name of the sdk to resolve.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        abstract public bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string foundPath,
            out bool userRequestedSpecificFile

        );
        /// <summary>
        /// Unify an assembly name according to the fx retarget rules.
        /// </summary>
        /// <param name="assemblyName">The unify-from assembly name.</param>
        /// <param name="unifiedVersion">The new version number.</param>
        /// <param name="isPrerequisite">Whether this assembly will be available on target machines.</param>
        /// <param name="isRedistRoot">May be true, false or null. Null means there was no IsRedistRoot in the redist list.</param>
        /// <param name="redistName">Name of the corresponding Resist specified in the redist list.</param>
        internal void GetInfo
        (
            AssemblyNameExtension assemblyName,
            out Version unifiedVersion,
            out bool isPrerequisite,
            out bool? isRedistRoot,
            out string redistName
        )
        {
            unifiedVersion = assemblyName.Version;
            isPrerequisite = false;
            isRedistRoot = null;
            redistName = null;


            // Short-circuit in cases where there is no redist list.
            if (_redistList == null)
            {
                return;
            }

            // If there's no version, for example in a simple name, then no remapping is possible,
            // and this is not a prerequisite.
            if (assemblyName.Version == null)
            {
                return;
            }

            AssemblyEntry highestVersionFromRedistList = FindHighestVersionInRedistList(assemblyName);

            // Could not find the assembly in the redist list. Return as there has been no redist list unification
            if (highestVersionFromRedistList == null)
            {
                return;
            }

            // Dont allow downgrading of reference version due to redist unification because this is automatic rather than something like an appconfig which 
            // has to be manually set. However if the major version is 255 then we do want to unify down the version number.
            if (assemblyName.Version <= highestVersionFromRedistList.AssemblyNameExtension.Version || assemblyName.Version.Major == 255)
            {
                unifiedVersion = highestVersionFromRedistList.AssemblyNameExtension.Version;
                isPrerequisite = _redistList.IsPrerequisiteAssembly(highestVersionFromRedistList.FullName);
                isRedistRoot = _redistList.IsRedistRoot(highestVersionFromRedistList.FullName);
                redistName = _redistList.RedistName(highestVersionFromRedistList.FullName);

                return;
            }
        }
Beispiel #18
0
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assembly name object of the assembly.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (assemblyName != null)
            {
                // {GAC} was passed in.
                string gacResolved = _getAssemblyPathInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion,
                    targetedRuntimeVersion, fileExists, fullFusionName: false, specificVersion: wantSpecificVersion);

                if (!string.IsNullOrEmpty(gacResolved) && fileExists(gacResolved))
                {
                    foundPath = gacResolved;
                    return true;
                }
                else
                {
                    // Record this as a location that was considered.
                    if (assembliesConsideredAndRejected != null)
                    {
                        ResolutionSearchLocation considered = new ResolutionSearchLocation();
                        considered.FileNameAttempted = assemblyName.FullName;
                        considered.SearchPath = searchPathElement;
                        considered.AssemblyName = assemblyName;
                        considered.Reason = NoMatchReason.NotInGac;
                        assembliesConsideredAndRejected.Add(considered);
                    }
                }
            }


            return false;
        }
Beispiel #19
0
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
        /// <param name="candidateAssemblyFiles">List of literal assembly file names to be considered when SearchPaths has {CandidateAssemblyFiles}.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (assemblyName != null)
            {
                // {GAC} was passed in.
                string gacResolved = GlobalAssemblyCache.GetLocation(_buildEngine, assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, false /*may not be a fusion name*/, fileExists, null /*Use default delegate in method*/, null /*Use default delegate in method*/, wantSpecificVersion);
                if (gacResolved != null && gacResolved.Length > 0 && fileExists(gacResolved))
                {
                    foundPath = gacResolved;
                    return true;
                }
                else
                {
                    // Record this as a location that was considered.
                    if (assembliesConsideredAndRejected != null)
                    {
                        ResolutionSearchLocation considered = new ResolutionSearchLocation();
                        considered.FileNameAttempted = assemblyName.FullName;
                        considered.SearchPath = searchPathElement;
                        considered.AssemblyName = assemblyName;
                        considered.Reason = NoMatchReason.NotInGac;
                        assembliesConsideredAndRejected.Add(considered);
                    }
                }
            }


            return false;
        }
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,

            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (rawFileNameCandidate != null)
            {
                // {RawFileName} was passed in.
                if (fileExists(rawFileNameCandidate))
                {
                    userRequestedSpecificFile = true;
                    foundPath = rawFileNameCandidate;
                    return true;
                }
                else
                {
                    if (assembliesConsideredAndRejected != null)
                    {
                        ResolutionSearchLocation considered = null;
                        considered = new ResolutionSearchLocation();
                        considered.FileNameAttempted = rawFileNameCandidate;
                        considered.SearchPath = searchPathElement;
                        considered.Reason = NoMatchReason.NotAFileNameOnDisk;
                        assembliesConsideredAndRejected.Add(considered);
                    }
                }
            }


            return false;
        }
 internal void GetInfo(AssemblyNameExtension assemblyName, out Version unifiedVersion, out bool isPrerequisite, out bool? isRedistRoot, out string redistName)
 {
     unifiedVersion = assemblyName.Version;
     isPrerequisite = false;
     isRedistRoot = 0;
     redistName = null;
     if ((this.redistList != null) && (assemblyName.Version != null))
     {
         AssemblyEntry entry = this.FindHighestVersionInRedistList(assemblyName);
         if ((entry != null) && (assemblyName.Version <= entry.AssemblyNameExtension.Version))
         {
             unifiedVersion = entry.AssemblyNameExtension.Version;
             isPrerequisite = this.redistList.IsPrerequisiteAssembly(entry.FullName);
             isRedistRoot = this.redistList.IsRedistRoot(entry.FullName);
             redistName = this.redistList.RedistName(entry.FullName);
         }
     }
 }
 internal bool CompareCulture(AssemblyNameExtension that)
 {
     System.Globalization.CultureInfo cultureInfo      = this.CultureInfo;
     System.Globalization.CultureInfo invariantCulture = that.CultureInfo;
     if (cultureInfo == null)
     {
         cultureInfo = System.Globalization.CultureInfo.InvariantCulture;
     }
     if (invariantCulture == null)
     {
         invariantCulture = System.Globalization.CultureInfo.InvariantCulture;
     }
     if (cultureInfo.LCID != invariantCulture.LCID)
     {
         return(false);
     }
     return(true);
 }
 public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (assemblyName != null)
     {
         AssemblyNameExtension highestVersionInRedist = GetHighestVersionInRedist(this.installedAssemblies, assemblyName);
         foreach (string str in this.frameworkPaths)
         {
             string str2 = base.ResolveFromDirectory(highestVersionInRedist, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, str, assembliesConsideredAndRejected);
             if (str2 != null)
             {
                 foundPath = str2;
                 return true;
             }
         }
     }
     return false;
 }
        /// <summary>
        /// Clone this assemblyNameExtension
        /// </summary>
        internal AssemblyNameExtension Clone()
        {
            AssemblyNameExtension newExtension = new AssemblyNameExtension();

            if (_asAssemblyName != null)
            {
                newExtension._asAssemblyName = (AssemblyName)_asAssemblyName.Clone();
            }

            newExtension._asString     = _asString;
            newExtension._isSimpleName = _isSimpleName;
            newExtension._hasProcessorArchitectureInFusionName = _hasProcessorArchitectureInFusionName;
            newExtension._remappedFrom = _remappedFrom;

            // We are cloning so we can now party on the object even if the parent was immutable
            newExtension._immutable = false;

            return(newExtension);
        }
Beispiel #25
0
        /// <summary>
        /// Clone this assemblyNameExtension
        /// </summary>
        internal AssemblyNameExtension Clone()
        {
            AssemblyNameExtension newExtension = new AssemblyNameExtension();

            if (asAssemblyName != null)
            {
                newExtension.asAssemblyName = asAssemblyName.CloneIfPossible();
            }

            newExtension.asString     = asString;
            newExtension.isSimpleName = isSimpleName;
            newExtension.hasProcessorArchitectureInFusionName = hasProcessorArchitectureInFusionName;
            newExtension.remappedFrom = remappedFrom;

            // We are cloning so we can now party on the object even if the parent was immutable
            newExtension.immutable = false;

            return(newExtension);
        }
 public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (assemblyName != null)
     {
         this.LazyInitialize();
         if (this.wasMatch)
         {
             AssemblyFoldersEx ex = new AssemblyFoldersEx(this.registryKeyRoot, this.targetRuntimeVersion, this.registryKeySuffix, this.osVersion, this.platform, this.getRegistrySubKeyNames, this.getRegistrySubKeyDefaultValue, base.targetProcessorArchitecture, this.openBaseKey);
             string str = null;
             foreach (string str2 in ex)
             {
                 string path = base.ResolveFromDirectory(assemblyName, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, str2, assembliesConsideredAndRejected);
                 if (path != null)
                 {
                     if (str == null)
                     {
                         str = path;
                     }
                     if ((base.targetProcessorArchitecture != ProcessorArchitecture.MSIL) && (base.targetProcessorArchitecture != ProcessorArchitecture.None))
                     {
                         foundPath = path;
                         return true;
                     }
                     AssemblyNameExtension extension = base.getAssemblyName(path);
                     if ((extension != null) && ((extension.AssemblyName.ProcessorArchitecture == ProcessorArchitecture.MSIL) || (extension.AssemblyName.ProcessorArchitecture == ProcessorArchitecture.None)))
                     {
                         foundPath = path;
                         return true;
                     }
                 }
             }
             if (str != null)
             {
                 foundPath = str;
                 return true;
             }
         }
     }
     return false;
 }
 private int CompareBaseNameToImpl(AssemblyNameExtension that)
 {
     if (this == that)
     {
         return(0);
     }
     if ((this.asAssemblyName != null) && (that.asAssemblyName != null))
     {
         if (this.asAssemblyName == that.asAssemblyName)
         {
             return(0);
         }
         return(string.Compare(this.asAssemblyName.Name, that.asAssemblyName.Name, StringComparison.OrdinalIgnoreCase));
     }
     if ((this.asString != null) && (that.asString != null))
     {
         return(CompareBaseNamesStringWise(this.asString, that.asString));
     }
     return(string.Compare(this.Name, that.Name, StringComparison.OrdinalIgnoreCase));
 }
 private int CompareBaseNameToImpl(AssemblyNameExtension that)
 {
     if (this == that)
     {
         return 0;
     }
     if ((this.asAssemblyName != null) && (that.asAssemblyName != null))
     {
         if (this.asAssemblyName == that.asAssemblyName)
         {
             return 0;
         }
         return string.Compare(this.asAssemblyName.Name, that.asAssemblyName.Name, StringComparison.OrdinalIgnoreCase);
     }
     if ((this.asString != null) && (that.asString != null))
     {
         return CompareBaseNamesStringWise(this.asString, that.asString);
     }
     return string.Compare(this.Name, that.Name, StringComparison.OrdinalIgnoreCase);
 }
        /// <summary>
        /// Allows the comparison of the culture.
        /// </summary>
        internal bool CompareCulture(AssemblyNameExtension that)
        {
            // Do the Cultures match?
            CultureInfo aCulture = CultureInfo;
            CultureInfo bCulture = that.CultureInfo;

            if (aCulture == null)
            {
                aCulture = CultureInfo.InvariantCulture;
            }
            if (bCulture == null)
            {
                bCulture = CultureInfo.InvariantCulture;
            }
            if (aCulture.LCID != bCulture.LCID)
            {
                return(false);
            }

            return(true);
        }
 internal static AssemblyNameExtension GetHighestVersionInRedist(InstalledAssemblies installedAssemblies, AssemblyNameExtension assemblyName)
 {
     AssemblyNameExtension extension = assemblyName;
     if ((extension.Version == null) && (installedAssemblies != null))
     {
         AssemblyEntry[] entryArray = installedAssemblies.FindAssemblyNameFromSimpleName(assemblyName.Name);
         if (entryArray.Length <= 1)
         {
             return extension;
         }
         for (int i = 0; i < entryArray.Length; i++)
         {
             AssemblyNameExtension that = new AssemblyNameExtension(entryArray[i].FullName);
             if (((that.Version != null) && (that.Version.CompareTo(extension.Version) > 0)) && assemblyName.PartialNameCompare(that, PartialComparisonFlags.PublicKeyToken | PartialComparisonFlags.Culture))
             {
                 extension = that;
             }
         }
     }
     return extension;
 }
        /// <summary>
        /// Given a strong name, find its path in the GAC.
        /// </summary>
        /// <param name="strongName">The strong name.</param>
        /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64.</param>
        /// <returns>The path to the assembly. Empty if none exists.</returns>
        private static string GetLocationImpl(AssemblyNameExtension assemblyName, string targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntime, FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
        {
            // Extra checks for PInvoke-destined data.
            ErrorUtilities.VerifyThrowArgumentNull(assemblyName, "assemblyName");
            ErrorUtilities.VerifyThrow(assemblyName.FullName != null, "Got a null assembly name fullname.");

            string strongName = assemblyName.FullName;

            if (targetProcessorArchitecture != null && !assemblyName.HasProcessorArchitectureInFusionName)
            {
                strongName += ", ProcessorArchitecture=" + targetProcessorArchitecture;
            }

            string assemblyPath = String.Empty;

            // Dictionary sorted by Version in reverse order, this will give the values enumeration the highest runtime version first.
            SortedDictionary<Version, SortedDictionary<AssemblyNameExtension, string>> assembliesByRuntime = GenerateListOfAssembliesByRuntime(strongName, getRuntimeVersion, targetedRuntime, fileExists, getPathFromFusionName, getGacEnumerator, specificVersion);
            if (assembliesByRuntime != null)
            {
                foreach (SortedDictionary<AssemblyNameExtension, string> runtimeBucket in assembliesByRuntime.Values)
                {
                    // Grab the first element if there are one or more elements. This will give us the highest version assembly name.
                    if (runtimeBucket.Count > 0)
                    {
                        foreach (KeyValuePair<AssemblyNameExtension, string> kvp in runtimeBucket)
                        {
                            assemblyPath = kvp.Value;
                            break;
                        }

                        if (!String.IsNullOrEmpty(assemblyPath))
                        {
                            break;
                        }
                    }
                }
            }

            return assemblyPath;
        }
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the &lt;AssemblyFolderKey&gt; on the reference in the project.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,

            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (assemblyName != null)
            {
                // {AssemblyFolders} was passed in.
                ICollection assemblyFolders = AssemblyFolder.GetAssemblyFolders(assemblyFolderKey);

                if (assemblyFolders != null)
                {
                    foreach (string assemblyFolder in assemblyFolders)
                    {
                        string resolvedPath = ResolveFromDirectory(assemblyName, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, assemblyFolder, assembliesConsideredAndRejected);
                        if (resolvedPath != null)
                        {
                            foundPath = resolvedPath;
                            return true;
                        }
                    }
                }
            }

            return false;
        }
        internal int CompareTo(AssemblyNameExtension that)
        {
            if (this.Equals(that))
            {
                return(0);
            }
            int num = this.CompareBaseNameTo(that);

            if (num != 0)
            {
                return(num);
            }
            if (!(this.Version != that.Version))
            {
                return(string.Compare(this.FullName, that.FullName, StringComparison.OrdinalIgnoreCase));
            }
            if (this.Version == null)
            {
                return(-1);
            }
            return(this.Version.CompareTo(that.Version));
        }
        /// <summary>
        /// Compare two base names as quickly as possible.
        /// </summary>
        /// <param name="that"></param>
        /// <returns></returns>
        internal int CompareBaseNameTo(AssemblyNameExtension that)
        {
            int result = CompareBaseNameToImpl(that);

#if DEBUG
            // Now, compare to the real value to make sure the result was accurate.
            AssemblyName a1 = _asAssemblyName;
            AssemblyName a2 = that._asAssemblyName;
            if (a1 == null)
            {
                a1 = new AssemblyName(_asString);
            }
            if (a2 == null)
            {
                a2 = new AssemblyName(that._asString);
            }

            int baselineResult = String.Compare(a1.Name, a2.Name, StringComparison.OrdinalIgnoreCase);
            ErrorUtilities.VerifyThrow(result == baselineResult, "Optimized version of CompareBaseNameTo didn't return the same result as the baseline.");
#endif
            return(result);
        }
 internal static string ResolveReference(IEnumerable<Microsoft.Build.Tasks.Resolver[]> jaggedResolvers, AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string resolvedSearchPath, out bool userRequestedSpecificFile)
 {
     userRequestedSpecificFile = false;
     resolvedSearchPath = string.Empty;
     foreach (Microsoft.Build.Tasks.Resolver[] resolverArray in jaggedResolvers)
     {
         if (resolverArray == null)
         {
             break;
         }
         foreach (Microsoft.Build.Tasks.Resolver resolver in resolverArray)
         {
             string str;
             if (resolver.Resolve(assemblyName, rawFileNameCandidate, isPrimaryProjectReference, wantSpecificVersion, executableExtensions, hintPath, assemblyFolderKey, assembliesConsideredAndRejected, out str, out userRequestedSpecificFile))
             {
                 resolvedSearchPath = resolver.SearchPath;
                 return str;
             }
         }
     }
     return null;
 }
        /// <summary>
        /// Clone this assemblyNameExtension
        /// </summary>
        internal AssemblyNameExtension Clone()
        {
            AssemblyNameExtension newExtension = new AssemblyNameExtension();

            if (asAssemblyName != null)
            {
#if FEATURE_ASSEMBLYNAME_CLONE
                newExtension.asAssemblyName = (AssemblyName)asAssemblyName.Clone();
#else
                newExtension.asAssemblyName = new AssemblyName(asAssemblyName.FullName);
#endif
            }

            newExtension.asString     = asString;
            newExtension.isSimpleName = isSimpleName;
            newExtension.hasProcessorArchitectureInFusionName = hasProcessorArchitectureInFusionName;
            newExtension.remappedFrom = remappedFrom;

            // We are cloning so we can now party on the object even if the parent was immutable
            newExtension.immutable = false;

            return(newExtension);
        }
 public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (assemblyName != null)
     {
         foreach (string str in this.candidateAssemblyFiles)
         {
             if (Microsoft.Build.Shared.FileUtilities.HasExtension(str, executableExtensions))
             {
                 bool flag2 = false;
                 ResolutionSearchLocation searchLocation = null;
                 if (assembliesConsideredAndRejected != null)
                 {
                     searchLocation = new ResolutionSearchLocation {
                         FileNameAttempted = str,
                         SearchPath = base.searchPathElement
                     };
                 }
                 if (base.FileMatchesAssemblyName(assemblyName, isPrimaryProjectReference, wantSpecificVersion, false, str, searchLocation))
                 {
                     flag2 = true;
                 }
                 else if (assembliesConsideredAndRejected != null)
                 {
                     assembliesConsideredAndRejected.Add(searchLocation);
                 }
                 if (flag2)
                 {
                     foundPath = str;
                     return true;
                 }
             }
         }
     }
     return false;
 }
 internal int CompareBaseNameTo(AssemblyNameExtension that)
 {
     return(this.CompareBaseNameToImpl(that));
 }
 internal bool PartialNameCompare(AssemblyNameExtension that)
 {
     return(this.PartialNameCompare(that, PartialComparisonFlags.Default));
 }
 /// <summary>
 /// Do a partial comparison between two assembly name extensions.
 /// Compare the fields of A and B on the following conditions:
 /// 1) A.Field has a non null value
 /// 2) The field has been selected in the comparison flags or the default comparison flags are passed in.
 ///
 /// If A.Field is null then we will not compare A.Field and B.Field even when the comparison flag is set for that field unless skipNullFields is false.
 /// </summary>
 internal bool PartialNameCompare(AssemblyNameExtension that, PartialComparisonFlags comparisonFlags)
 {
     return(PartialNameCompare(that, comparisonFlags, false /* do not consider retargetable flag*/));
 }
 /// <summary>
 /// Compare the fields of this with that if they are not null.
 /// </summary>
 internal bool PartialNameCompare(AssemblyNameExtension that, bool considerRetargetableFlag)
 {
     return(PartialNameCompare(that, PartialComparisonFlags.Default, considerRetargetableFlag));
 }
        /// <summary>
        /// Compare two assembly names for equality.
        /// </summary>
        /// <param name="that"></param>
        /// <returns></returns>
        private bool EqualsImpl(AssemblyNameExtension that, bool ignoreVersion, bool considerRetargetableFlag)
        {
            // Pointer compare.
            if (Object.ReferenceEquals(this, that))
            {
                return(true);
            }

            // If that is null then this and that are not equal. Also, this would cause a crash on the next line.
            if (Object.ReferenceEquals(that, null))
            {
                return(false);
            }

            // Do both have assembly names?
            if (_asAssemblyName != null && that._asAssemblyName != null)
            {
                // Pointer compare.
                if (Object.ReferenceEquals(_asAssemblyName, that._asAssemblyName))
                {
                    return(true);
                }
            }

            // Do both have strings that equal each-other?
            if (_asString != null && that._asString != null)
            {
                if (_asString == that._asString)
                {
                    return(true);
                }

                // If they weren't identical then they might still differ only by
                // case. So we can't assume that they don't match. So fall through...
            }

            // Do the names match?
            if (0 != String.Compare(Name, that.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!ignoreVersion && (this.Version != that.Version))
            {
                return(false);
            }

            if (!CompareCulture(that))
            {
                return(false);
            }

            if (!ComparePublicKeyToken(that))
            {
                return(false);
            }

            if (considerRetargetableFlag && this.Retargetable != that.Retargetable)
            {
                return(false);
            }

            return(true);
        }
 internal bool ComparePublicKeyToken(AssemblyNameExtension that)
 {
     byte[] publicKeyToken = this.GetPublicKeyToken();
     byte[] bPKT           = that.GetPublicKeyToken();
     return(ComparePublicKeyTokens(publicKeyToken, bPKT));
 }
 /// <summary>
 /// Compare two assembly names for equality ignoring version.
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 internal bool EqualsIgnoreVersion(AssemblyNameExtension that)
 {
     return(EqualsImpl(that, true, false));
 }
 /// <summary>
 /// Compare two assembly names for equality.
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 internal bool Equals(AssemblyNameExtension that)
 {
     return(EqualsImpl(that, false, false));
 }
 /// <summary>
 /// Compare one assembly name to another.
 /// </summary>
 /// <param name="that"></param>
 /// <returns></returns>
 internal int CompareTo(AssemblyNameExtension that)
 {
     return(CompareTo(that, false));
 }
 /// <summary>
 /// Add an assemblyNameExtension which represents an assembly name which was mapped to THIS assemblyName.
 /// </summary>
 internal void AddRemappedAssemblyName(AssemblyNameExtension extensionToAdd)
 {
     ErrorUtilities.VerifyThrow(extensionToAdd.Immutable, "ExtensionToAdd is not immutable");
     InitializeRemappedFrom();
     _remappedFrom.Add(extensionToAdd);
 }
Beispiel #48
0
        /// <summary>
        /// Attempts to convert an itemSpec and fusionName into an assembly name.
        /// AssemblyName is left unchanged if conversion wasn't possible.
        /// </summary>
        /// <param name="itemSpec"></param>
        /// <param name="fusionName"></param>
        /// <param name="assemblyName"></param>
        private static void TryConvertToAssemblyName(string itemSpec, string fusionName, ref AssemblyNameExtension assemblyName)
        {
            // FusionName is used if available.
            string finalName = fusionName;
            if (finalName == null || finalName.Length == 0)
            {
                // Otherwise, its itemSpec.
                finalName = itemSpec;
            }

            bool pathRooted = false;
            try
            {
                pathRooted = Path.IsPathRooted(finalName);
            }
            catch (ArgumentException)
            {
                /* Eat this because it has invalid chars in to and cannot be a path, maybe it can be parsed as a fusion name.*/
            }

            if (!pathRooted)
            {
                // Now try to convert to an AssemblyName.
                try
                {
                    assemblyName = new AssemblyNameExtension(finalName, true /*throw if not valid*/);
                }
                catch (System.IO.FileLoadException)
                {
                    // Not a valid AssemblyName. Maybe its a file name.
                    TryGatherAssemblyNameEssentials(finalName, ref assemblyName);
                    return;
                }
            }
            else
            {
                // Maybe the string has a fusion name inside of it.
                TryGatherAssemblyNameEssentials(finalName, ref assemblyName);
            }
        }
Beispiel #49
0
        /// <summary>
        /// Given a string that may be a fusion name, try to gather the four essential properties:
        ///     Name
        ///     Version
        ///     PublicKeyToken
        ///     Culture
        /// </summary>
        /// <param name="fusionName"></param>
        /// <param name="assemblyName"></param>
        private static void TryGatherAssemblyNameEssentials(string fusionName, ref AssemblyNameExtension assemblyName)
        {
            int firstComma = fusionName.IndexOf(',');
            if (firstComma == -1)
            {
                return;
            }
            string name = fusionName.Substring(0, firstComma);

            string version = null;
            string publicKeyToken = null;
            string culture = null;
            TryGetAssemblyNameComponent(fusionName, "Version", ref version);
            TryGetAssemblyNameComponent(fusionName, "PublicKeyToken", ref publicKeyToken);
            TryGetAssemblyNameComponent(fusionName, "Culture", ref culture);

            if (version == null || publicKeyToken == null || culture == null)
            {
                return;
            }

            string newFusionName = String.Format(CultureInfo.InvariantCulture,
                "{0}, Version={1}, Culture={2}, PublicKeyToken={3}",
                name, version, culture, publicKeyToken);

            // Now try to convert to an AssemblyName.
            try
            {
                assemblyName = new AssemblyNameExtension(newFusionName, true /* throw if not valid */);
            }
            catch (System.IO.FileLoadException)
            {
                // Not a valid AssemblyName. Maybe its a file name.
                // TryGatherAssemblyNameEssentials
                return;
            }
        }
 /// <summary>
 /// Compare two assembly names and consider the retargetable flag during the comparison
 /// </summary>
 internal bool Equals(AssemblyNameExtension that, bool considerRetargetableFlag)
 {
     return(EqualsImpl(that, false, considerRetargetableFlag));
 }