/// <summary> /// Get unification information for the given assembly name. /// </summary> /// <param name="assemblyName">The assembly name.</param> /// <param name="unifiedVersion">The new version of the assembly to use.</param> /// <param name="unificationReason">The reason this reference was unified.</param> /// <param name="isPrerequisite">True if this is a prereq assembly.</param> /// <returns>True if there was a unification.</returns> private bool UnifyAssemblyNameVersions ( AssemblyNameExtension assemblyName, out Version unifiedVersion, out UnificationReason unificationReason, out bool isPrerequisite, out bool? isRedistRoot, out string redistName ) { unifiedVersion = assemblyName.Version; isPrerequisite = false; isRedistRoot = null; redistName = null; unificationReason = UnificationReason.DidntUnify; // If there's no version, for example in a simple name, then no remapping is possible. if (assemblyName.Version == null) { return false; } // Try for a remapped assemblies unification. if (_remappedAssemblies != null) { foreach (DependentAssembly remappedAssembly in _remappedAssemblies) { // First, exclude anything without the simple name match AssemblyNameExtension comparisonAssembly = new AssemblyNameExtension((AssemblyName)remappedAssembly.PartialAssemblyName.Clone()); if (assemblyName.CompareBaseNameTo(comparisonAssembly) == 0) { // Comparison assembly is a partial name. Give it our version. comparisonAssembly.ReplaceVersion(assemblyName.Version); if (assemblyName.Equals(comparisonAssembly)) { foreach (BindingRedirect bindingRedirect in remappedAssembly.BindingRedirects) { if (assemblyName.Version >= bindingRedirect.OldVersionLow && assemblyName.Version <= bindingRedirect.OldVersionHigh) { // If the new version is different than the old version, then there is a unification. if (assemblyName.Version != bindingRedirect.NewVersion) { unifiedVersion = bindingRedirect.NewVersion; unificationReason = UnificationReason.BecauseOfBindingRedirect; return true; } } } } } } } // Try for an installed assemblies unification. if (_installedAssemblies != null) { _installedAssemblies.GetInfo ( assemblyName, out unifiedVersion, out isPrerequisite, out isRedistRoot, out redistName ); // Was there a unification? if (unifiedVersion != assemblyName.Version) { unificationReason = UnificationReason.FrameworkRetarget; return assemblyName.Version != unifiedVersion; } } return false; }
private IEnumerable<UnifiedAssemblyName> GetUnifiedAssemblyNames(IEnumerable<AssemblyNameExtension> preUnificationAssemblyNames) { foreach (AssemblyNameExtension iteratorVariable0 in preUnificationAssemblyNames) { UnificationReason iteratorVariable6; string iteratorVariable5; bool? iteratorVariable4; bool iteratorVariable3; Version iteratorVariable2; string name = iteratorVariable0.Name; AssemblyNameExtension assemblyName = new AssemblyNameExtension((AssemblyName) iteratorVariable0.AssemblyName.Clone()); bool isUnified = this.UnifyAssemblyNameVersions(assemblyName, out iteratorVariable2, out iteratorVariable6, out iteratorVariable3, out iteratorVariable4, out iteratorVariable5); assemblyName.ReplaceVersion(iteratorVariable2); yield return new UnifiedAssemblyName(iteratorVariable0, assemblyName, isUnified, iteratorVariable6, iteratorVariable3, iteratorVariable4, iteratorVariable5); } }
/// <summary> /// Given an enumerator of pre-unified assembly names, return an enumerator of unified /// assembly names. /// </summary> /// <param name="preUnificationAssemblyName"></param> /// <returns></returns> private IEnumerable<UnifiedAssemblyName> GetUnifiedAssemblyNames ( IEnumerable<AssemblyNameExtension> preUnificationAssemblyNames ) { foreach (AssemblyNameExtension preUnificationAssemblyName in preUnificationAssemblyNames) { string name = preUnificationAssemblyName.Name; // First, unify the assembly name so that we're dealing with the right version. // Not AssemblyNameExtension because we're going to write to it. AssemblyNameExtension dependentAssembly = new AssemblyNameExtension((AssemblyName)preUnificationAssemblyName.AssemblyName.Clone()); Version unifiedVersion; bool isPrerequisite; bool? isRedistRoot; string redistName; UnificationReason unificationReason; bool isUnified = UnifyAssemblyNameVersions(dependentAssembly, out unifiedVersion, out unificationReason, out isPrerequisite, out isRedistRoot, out redistName); dependentAssembly.ReplaceVersion(unifiedVersion); yield return new UnifiedAssemblyName(preUnificationAssemblyName, dependentAssembly, isUnified, unificationReason, isPrerequisite, isRedistRoot, redistName); } }
private bool UnifyAssemblyNameVersions(AssemblyNameExtension assemblyName, out Version unifiedVersion, out UnificationReason unificationReason, out bool isPrerequisite, out bool? isRedistRoot, out string redistName) { unifiedVersion = assemblyName.Version; isPrerequisite = false; isRedistRoot = 0; redistName = null; unificationReason = UnificationReason.DidntUnify; if (assemblyName.Version != null) { if (this.remappedAssemblies != null) { foreach (DependentAssembly assembly in this.remappedAssemblies) { AssemblyNameExtension that = new AssemblyNameExtension((AssemblyName) assembly.PartialAssemblyName.Clone()); if (assemblyName.CompareBaseNameTo(that) == 0) { that.ReplaceVersion(assemblyName.Version); if (assemblyName.Equals(that)) { foreach (BindingRedirect redirect in assembly.BindingRedirects) { if (((assemblyName.Version >= redirect.OldVersionLow) && (assemblyName.Version <= redirect.OldVersionHigh)) && (assemblyName.Version != redirect.NewVersion)) { unifiedVersion = redirect.NewVersion; unificationReason = UnificationReason.BecauseOfBindingRedirect; return true; } } } } } } if (this.installedAssemblies != null) { this.installedAssemblies.GetInfo(assemblyName, out unifiedVersion, out isPrerequisite, out isRedistRoot, out redistName); if (unifiedVersion != assemblyName.Version) { unificationReason = UnificationReason.FrameworkRetarget; return (assemblyName.Version != unifiedVersion); } } } return false; }