Example #1
0
        /// <summary>
        /// If the version is not set for an assembly reference, go through the redist list and find the highest version for that assembly.
        /// Make sure when matching the assembly in the redist that we take into account the publicKeyToken and the Culture.
        /// </summary>
        internal static AssemblyNameExtension GetHighestVersionInRedist(InstalledAssemblies installedAssemblies, AssemblyNameExtension assemblyName)
        {
            AssemblyNameExtension assemblyNameToUse = assemblyName;

            if ((assemblyNameToUse.Version == null && installedAssemblies != null))
            {
                // If there are multiple entries in the redist list for this assembly, let's
                // pick the one with the highest version and resolve it.
                foreach (AssemblyEntry a in installedAssemblies.FindAssemblyNameFromSimpleName(assemblyName.Name))
                {
                    var current = new AssemblyNameExtension(a.FullName);

                    // If the current version is higher than the previously looked at.
                    if (current.Version != null && current.Version.CompareTo(assemblyNameToUse.Version) > 0)
                    {
                        // Only compare the Culture and the public key token, the simple names will ALWAYS be the same and the version we do not care about.
                        if (assemblyName.PartialNameCompare(current, PartialComparisonFlags.Culture | PartialComparisonFlags.PublicKeyToken))
                        {
                            assemblyNameToUse = current;
                        }
                    }
                }
            }

            return(assemblyNameToUse);
        }
 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;
 }
Example #3
0
        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>
        /// If the version is not set for an assembly reference, go through the redist list and find the highest version for that assembly.
        /// Make sure when matching the assembly in the redist that we take into account the publicKeyToken and the Culture.
        /// </summary>
        internal static AssemblyNameExtension GetHighestVersionInRedist(InstalledAssemblies installedAssemblies, AssemblyNameExtension assemblyName)
        {
            AssemblyNameExtension assemblyNameToUse = assemblyName;

            if ((assemblyNameToUse.Version == null && installedAssemblies != null))
            {
                // If there are multiple entries in the redist list for this assembly, let's
                // pick the one with the highest version and resolve it.

                AssemblyEntry[] assemblyEntries = installedAssemblies.FindAssemblyNameFromSimpleName(assemblyName.Name);

                if (assemblyEntries.Length != 0)
                {
                    for (int i = 0; i < assemblyEntries.Length; ++i)
                    {
                        AssemblyNameExtension current = new AssemblyNameExtension(assemblyEntries[i].FullName);

                        // If the current version is higher than the previously looked at.
                        if (current.Version != null && current.Version.CompareTo(assemblyNameToUse.Version) > 0)
                        {
                            // Only compare the Culture and the public key token, the simple names will ALWAYS be the same and the version we do not care about.
                            if (assemblyName.PartialNameCompare(current, PartialComparisonFlags.Culture | PartialComparisonFlags.PublicKeyToken))
                            {
                                assemblyNameToUse = current;
                            }
                        }
                    }
                }
            }

            return assemblyNameToUse;
        }