Exemple #1
0
        private static SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> > GenerateListOfAssembliesByRuntime(string strongName, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntime, Microsoft.Build.Shared.FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
        {
            Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(targetedRuntime, "targetedRuntime");
            IEnumerable <AssemblyNameExtension> enumerable = getGacEnumerator(strongName);
            SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> > dictionary = new SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> >(ReverseVersionGenericComparer.Comparer);

            if (enumerable != null)
            {
                foreach (AssemblyNameExtension extension in enumerable)
                {
                    string str = getPathFromFusionName(extension.FullName);
                    if (!string.IsNullOrEmpty(str) && fileExists(str))
                    {
                        Version version = VersionUtilities.ConvertToVersion(getRuntimeVersion(str));
                        if ((version != null) && ((targetedRuntime.CompareTo(version) >= 0) || specificVersion))
                        {
                            SortedDictionary <AssemblyNameExtension, string> dictionary2 = null;
                            dictionary.TryGetValue(version, out dictionary2);
                            if (dictionary2 == null)
                            {
                                dictionary2 = new SortedDictionary <AssemblyNameExtension, string>(AssemblyNameReverseVersionComparer.GenericComparer);
                                dictionary.Add(version, dictionary2);
                            }
                            if (!dictionary2.ContainsKey(extension))
                            {
                                dictionary2.Add(extension, str);
                            }
                        }
                    }
                }
            }
            return(dictionary);
        }
        internal static ArrayList GatherVersionStrings(string targetRuntimeVersion, IEnumerable versions)
        {
            ArrayList c       = new ArrayList();
            Version   version = VersionUtilities.ConvertToVersion(targetRuntimeVersion);
            ArrayList list2   = new ArrayList();
            SortedDictionary <Version, ArrayList> targetFrameworkVersionToRegistryVersions = new SortedDictionary <Version, ArrayList>(ReverseVersionGenericComparer.Comparer);

            foreach (string str in versions)
            {
                if ((str.Length > 0) && (string.Compare(str.Substring(0, 1), "v", StringComparison.OrdinalIgnoreCase) == 0))
                {
                    Version version2 = VersionUtilities.ConvertToVersion(str);
                    if (version2 == null)
                    {
                        if (string.Compare(str, 0, targetRuntimeVersion, 0, targetRuntimeVersion.Length, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            c.Add(str);
                        }
                    }
                    else
                    {
                        Version candidateVersion = null;
                        if (version2.Build > 0xff)
                        {
                            candidateVersion = new Version(version2.Major, version2.Minor);
                        }
                        else if (version2.Revision != -1)
                        {
                            candidateVersion = new Version(version2.Major, version2.Minor, version2.Build);
                        }
                        else
                        {
                            candidateVersion = version2;
                        }
                        bool flag = false;
                        if ((version == null) && (string.Compare(str, 0, targetRuntimeVersion, 0, targetRuntimeVersion.Length, StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            flag = true;
                        }
                        bool flag2 = (version != null) && (version >= candidateVersion);
                        if ((candidateVersion != null) && (flag2 || flag))
                        {
                            AddCandidateVersion(targetFrameworkVersionToRegistryVersions, str, candidateVersion);
                        }
                    }
                }
            }
            foreach (KeyValuePair <Version, ArrayList> pair in targetFrameworkVersionToRegistryVersions)
            {
                ArrayList list3 = pair.Value;
                list3.Sort(ReverseVersionComparer.Comparer);
                foreach (string str2 in list3)
                {
                    list2.Add(str2);
                }
            }
            list2.AddRange(c);
            return(list2);
        }
Exemple #3
0
        /// <summary>
        /// Enumerate the gac and generate a list of assemblies which match the strongname by runtime.
        /// </summary>
        private static SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> > GenerateListOfAssembliesByRuntime(string strongName, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntime, FileExists fileExists, GetPathFromFusionName getPathFromFusionName, GetGacEnumerator getGacEnumerator, bool specificVersion)
        {
            ErrorUtilities.VerifyThrowArgumentNull(targetedRuntime, "targetedRuntime");

            IEnumerable <AssemblyNameExtension> gacEnum = getGacEnumerator(strongName);

            // Dictionary of Runtime version (sorted in reverse order) to a list of assemblies which are part of that runtime. This will allow us to pick the highest runtime and version first.
            SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> > assembliesWithValidRuntimes = new SortedDictionary <Version, SortedDictionary <AssemblyNameExtension, string> >(ReverseVersionGenericComparer.Comparer);

            // Enumerate the gac values returned based on the partial or full fusion name.
            if (gacEnum != null)
            {
                foreach (AssemblyNameExtension gacAssembly in gacEnum)
                {
                    // We only have a fusion name from the IAssemblyName interface we need to get the path to the assembly to resolve it and to check its runtime.
                    string assemblyPath = getPathFromFusionName(gacAssembly.FullName);

                    // Make sure we could get the path from the Fusion name and make sure the file actually exists.
                    if (!String.IsNullOrEmpty(assemblyPath) && fileExists(assemblyPath))
                    {
                        // Get the runtime version from the found assembly.
                        string runtimeVersionRaw = getRuntimeVersion(assemblyPath);

                        // Convert the runtime string to a version so we can properly compare them as per version object comparison rules.
                        // We will accept version which are less than or equal to the targeted runtime.
                        Version runtimeVersion = VersionUtilities.ConvertToVersion(runtimeVersionRaw);

                        // Make sure the targeted runtime is greater than or equal to the runtime version of the assembly we got from the gac.
                        if (runtimeVersion != null)
                        {
                            if (targetedRuntime.CompareTo(runtimeVersion) >= 0 || specificVersion)
                            {
                                SortedDictionary <AssemblyNameExtension, string> assembliesWithRuntime = null;
                                assembliesWithValidRuntimes.TryGetValue(runtimeVersion, out assembliesWithRuntime);

                                // Create a new list if one does not exist.
                                if (assembliesWithRuntime == null)
                                {
                                    assembliesWithRuntime = new SortedDictionary <AssemblyNameExtension, string>(AssemblyNameReverseVersionComparer.GenericComparer);
                                    assembliesWithValidRuntimes.Add(runtimeVersion, assembliesWithRuntime);
                                }

                                if (!assembliesWithRuntime.ContainsKey(gacAssembly))
                                {
                                    // Add the assembly to the list
                                    assembliesWithRuntime.Add(gacAssembly, assemblyPath);
                                }
                            }
                        }
                    }
                }
            }

            return(assembliesWithValidRuntimes);
        }
        private bool IsVersionInsideRange(Version v, RegistryKey keyPlatform)
        {
            bool flag = true;

            if (v != null)
            {
                string  str     = keyPlatform.GetValue("MinOSVersion", null) as string;
                Version version = (str == null) ? null : VersionUtilities.ConvertToVersion(str);
                if ((version != null) && (version > v))
                {
                    flag = false;
                }
                string  str2     = keyPlatform.GetValue("MaxOSVersion", null) as string;
                Version version2 = (str2 == null) ? null : VersionUtilities.ConvertToVersion(str2);
                if ((version2 != null) && (version2 < v))
                {
                    flag = false;
                }
            }
            return(flag);
        }
        private void FindDirectories(RegistryView view, RegistryHive hive, string registryKeyRoot, string targetRuntimeVersion, string registryKeySuffix, string osVersion, string platform, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, OpenBaseKey openBaseKey)
        {
            RegistryKey baseKey  = openBaseKey(hive, view);
            IEnumerable versions = getRegistrySubKeyNames(baseKey, registryKeyRoot);

            if (versions != null)
            {
                ArrayList list  = GatherVersionStrings(targetRuntimeVersion, versions);
                ArrayList list2 = new ArrayList();
                ReverseVersionComparer comparer = ReverseVersionComparer.Comparer;
                foreach (string str in list)
                {
                    string      subKey      = registryKeyRoot + @"\" + str + @"\" + registryKeySuffix;
                    IEnumerable enumerable2 = getRegistrySubKeyNames(baseKey, subKey);
                    ArrayList   list3       = new ArrayList();
                    foreach (string str3 in enumerable2)
                    {
                        list3.Add(str3);
                    }
                    list3.Sort(comparer);
                    foreach (string str4 in list3)
                    {
                        list2.Add(subKey + @"\" + str4);
                    }
                }
                ArrayList list4 = new ArrayList();
                foreach (string str5 in list2)
                {
                    IEnumerable enumerable3 = getRegistrySubKeyNames(baseKey, str5);
                    ArrayList   c           = new ArrayList();
                    foreach (string str6 in enumerable3)
                    {
                        c.Add(str5 + @"\" + str6);
                    }
                    c.Sort(comparer);
                    list4.AddRange(c);
                    list4.Add(str5);
                }
                foreach (string str7 in list4)
                {
                    if (!string.IsNullOrEmpty(platform) || !string.IsNullOrEmpty(osVersion))
                    {
                        RegistryKey keyPlatform = baseKey.OpenSubKey(str7, false);
                        if ((keyPlatform != null) && (keyPlatform.ValueCount > 0))
                        {
                            if ((platform != null) && (platform.Length > 0))
                            {
                                string str8 = keyPlatform.GetValue("Platform", null) as string;
                                if (!string.IsNullOrEmpty(str8) && !this.MatchingPlatformExists(platform, str8))
                                {
                                    continue;
                                }
                            }
                            if ((osVersion != null) && (osVersion.Length > 0))
                            {
                                Version v = VersionUtilities.ConvertToVersion(osVersion);
                                if (!this.IsVersionInsideRange(v, keyPlatform))
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    string str9 = getRegistrySubKeyDefaultValue(baseKey, str7);
                    if (str9 != null)
                    {
                        this.directoryNames.Add(str9);
                    }
                }
            }
        }