From c40e4c22d0b1752eb5f8820ce83063e34f123875 Mon Sep 17 00:00:00 2001 From: Marcio Rinaldi Date: Fri, 18 Sep 2015 18:04:11 -0300 Subject: [PATCH] Includes only the assemblies from the target platform in binding redirects --- src/Paket.Core/BindingRedirects.fs | 44 +++++++++++++++-------- src/Paket.Core/InstallProcess.fs | 56 +++++++++++++++++------------- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/Paket.Core/BindingRedirects.fs b/src/Paket.Core/BindingRedirects.fs index 6406f2cd9a..dd07204e10 100644 --- a/src/Paket.Core/BindingRedirects.fs +++ b/src/Paket.Core/BindingRedirects.fs @@ -1,4 +1,4 @@ -module Paket.BindingRedirects +module Paket.BindingRedirects open System open System.Text @@ -6,7 +6,9 @@ open System.Xml open System.Xml.Linq open System.IO open System.Reflection +open System.Runtime.Versioning open Paket.Xml.Linq +open Paket.FrameworkConversion /// Represents a binding redirection type BindingRedirect = @@ -68,19 +70,6 @@ let internal indentAssemblyBindings config = let newAssemblyBindingNode = XElement.Parse(sb.ToString(), LoadOptions.PreserveWhitespace) parent.Add(newAssemblyBindingNode) -/// Applies a set of binding redirects to a single configuration file. -let private applyBindingRedirects bindingRedirects (configFilePath:string) = - let config = - try - XDocument.Load(configFilePath, LoadOptions.PreserveWhitespace) - with - | :? System.Xml.XmlException as ex -> - Logging.verbosefn "Illegal XML in file: %s" configFilePath - raise ex - let config = Seq.fold setRedirect config bindingRedirects - indentAssemblyBindings config - config.Save configFilePath - let private configFiles = [ "app"; "web" ] |> Set.ofList let private projectFiles = [ ".csproj"; ".vbproj"; ".fsproj" ] |> Set.ofList let private toLower (s:string) = s.ToLower() @@ -118,6 +107,33 @@ let private addConfigFileToProject projectFile = |> ignore project.Save()) +/// Applies a set of binding redirects to a single configuration file. +let private applyBindingRedirects bindingRedirects (configFilePath:string) = + let projectFile = + getProjectFilesInDirectory (Path.GetDirectoryName(configFilePath)) + |> Seq.map ProjectFile.Load + |> Seq.tryHead + |> Option.bind id + + let bindingRedirects = + match projectFile with + | None -> Seq.empty + | Some p -> + FrameworkName(p.TargetFramework) + |> convertToFrameworkIdentifier + |> bindingRedirects + + let config = + try + XDocument.Load(configFilePath, LoadOptions.PreserveWhitespace) + with + | :? System.Xml.XmlException as ex -> + Logging.verbosefn "Illegal XML in file: %s" configFilePath + raise ex + let config = Seq.fold setRedirect config bindingRedirects + indentAssemblyBindings config + config.Save configFilePath + /// Applies a set of binding redirects to all .config files in a specific folder. let applyBindingRedirectsToFolder createNewBindingFiles rootPath bindingRedirects = if createNewBindingFiles then diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index db3882cdb2..9bded8c736 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -1,4 +1,4 @@ -/// Contains methods for the install process. +/// Contains methods for the install process. module Paket.InstallProcess open Paket @@ -138,30 +138,36 @@ let createModel(root, force, dependenciesFile:DependenciesFile, lockFile : LockF /// Applies binding redirects for all strong-named references to all app. and web. config files. let private applyBindingRedirects createNewBindingFiles root (extractedPackages:seq<_*InstallModel>) = - extractedPackages - |> Seq.map (fun (package, model:InstallModel) -> model.GetLibReferencesLazy.Force()) - |> Set.unionMany - |> Seq.choose(function | Reference.Library path -> Some path | _-> None) - |> Seq.groupBy (fun p -> FileInfo(p).Name) - |> Seq.choose(fun (_,librariesForPackage) -> - librariesForPackage - |> Seq.choose(fun library -> - try - let assembly = Assembly.ReflectionOnlyLoadFrom library - assembly - |> BindingRedirects.getPublicKeyToken - |> Option.map(fun token -> assembly, token) - with exn -> None) - |> Seq.sortBy(fun (assembly,_) -> assembly.GetName().Version) - |> Seq.toList - |> List.rev - |> function | head :: _ -> Some head | _ -> None) - |> Seq.map(fun (assembly, token) -> - { BindingRedirect.AssemblyName = assembly.GetName().Name - Version = assembly.GetName().Version.ToString() - PublicKeyToken = token - Culture = None }) - |> applyBindingRedirectsToFolder createNewBindingFiles root + let bindingRedirects (frameworkIdentifier : FrameworkIdentifier option) = + extractedPackages + |> Seq.map (fun (package, model:InstallModel) -> + match frameworkIdentifier with + | Some x -> model.GetLibReferences(x) + | None -> + model.GetLibReferencesLazy.Force() + |> Seq.choose(function | Reference.Library path -> Some path | _-> None)) + |> Seq.concat + |> Seq.groupBy (fun p -> FileInfo(p).Name) + |> Seq.choose(fun (_,librariesForPackage) -> + librariesForPackage + |> Seq.choose(fun library -> + try + let assembly = Assembly.ReflectionOnlyLoadFrom library + assembly + |> BindingRedirects.getPublicKeyToken + |> Option.map(fun token -> assembly, token) + with exn -> None) + |> Seq.sortBy(fun (assembly,_) -> assembly.GetName().Version) + |> Seq.toList + |> List.rev + |> function | head :: _ -> Some head | _ -> None) + |> Seq.map(fun (assembly, token) -> + { BindingRedirect.AssemblyName = assembly.GetName().Name + Version = assembly.GetName().Version.ToString() + PublicKeyToken = token + Culture = None }) + + applyBindingRedirectsToFolder createNewBindingFiles root bindingRedirects let findAllReferencesFiles root = root