From 142e28d4517cfbffd9a3f7910de06c38f6cdef81 Mon Sep 17 00:00:00 2001 From: Marcio Rinaldi Date: Mon, 2 Nov 2015 19:36:06 -0200 Subject: [PATCH] Adds only required binding redirects --- .../Paket.IntegrationTests/BindingRedirect.fs | 24 +++---- src/Paket.Core/InstallProcess.fs | 63 +++++++++++-------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/integrationtests/Paket.IntegrationTests/BindingRedirect.fs b/integrationtests/Paket.IntegrationTests/BindingRedirect.fs index 5ab716e9e4..8b0cbc1105 100644 --- a/integrationtests/Paket.IntegrationTests/BindingRedirect.fs +++ b/integrationtests/Paket.IntegrationTests/BindingRedirect.fs @@ -6,7 +6,7 @@ open NUnit.Framework open FsUnit [] -let ``install should redirect referenced assemblies only``() = +let ``install should redirect required assemblies only``() = paket "install --redirects --createnewbindingfiles" "binding-redirect-adds-referenced-assemblies-only" |> ignore let path = Path.Combine(scenarioTempPath "binding-redirect-adds-referenced-assemblies-only") @@ -34,22 +34,22 @@ let ``install should redirect referenced assemblies only``() = config1 |> shouldContainText Albedo config1 |> shouldContainText AutoFixture - config1 |> shouldContainText ``AutoFixture.Idioms`` - config1 |> shouldContainText ``AutoFixture.Xunit`` - config1 |> shouldContainText log4net + config1.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config1.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config1.Contains log4net |> shouldEqual false config1 |> shouldContainText ``Newtonsoft.Json`` - config1 |> shouldContainText ``Newtonsoft.Json.Schema`` - config1 |> shouldContainText xunit + config1.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config1.Contains xunit |> shouldEqual false config1 |> shouldContainText ``xunit.extensions`` config1 |> shouldContainText ``Castle.Core`` - config1 |> shouldContainText ``Castle.Windsor`` + config1.Contains ``Castle.Windsor`` |> shouldEqual false config2.Contains Albedo |> shouldEqual false config2.Contains AutoFixture |> shouldEqual false config2.Contains ``AutoFixture.Idioms`` |> shouldEqual false config2.Contains ``AutoFixture.Xunit`` |> shouldEqual false config2.Contains log4net |> shouldEqual false - config2 |> shouldContainText ``Newtonsoft.Json`` + config2.Contains ``Newtonsoft.Json`` |> shouldEqual false config2.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false config2.Contains xunit |> shouldEqual false config2.Contains ``xunit.extensions`` |> shouldEqual false @@ -60,13 +60,13 @@ let ``install should redirect referenced assemblies only``() = config3.Contains AutoFixture |> shouldEqual false config3.Contains ``AutoFixture.Idioms`` |> shouldEqual false config3.Contains ``AutoFixture.Xunit`` |> shouldEqual false - config3 |> shouldContainText log4net + config3.Contains log4net |> shouldEqual false config3 |> shouldContainText ``Newtonsoft.Json`` - config3 |> shouldContainText ``Newtonsoft.Json.Schema`` + config3.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false config3.Contains xunit |> shouldEqual false config3.Contains ``xunit.extensions`` |> shouldEqual false config3 |> shouldContainText ``Castle.Core`` - config3 |> shouldContainText ``Castle.Windsor`` + config3.Contains ``Castle.Windsor`` |> shouldEqual false config4.Contains Albedo |> shouldEqual false config4.Contains AutoFixture |> shouldEqual false @@ -78,4 +78,4 @@ let ``install should redirect referenced assemblies only``() = config4.Contains xunit |> shouldEqual false config4.Contains ``xunit.extensions`` |> shouldEqual false config4 |> shouldContainText ``Castle.Core`` - config4 |> shouldContainText ``Castle.Windsor`` + config4.Contains ``Castle.Windsor`` |> shouldEqual false diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index 235f6a96fc..04be12a005 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -181,33 +181,42 @@ let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) createNewBindingF match ProjectFile.FindReferencesFile (FileInfo projectFile.FileName) with | Some fileName -> let dependencies = dependencies projectFile - extractedPackages - |> Seq.map snd - |> Seq.filter (fun model -> dependencies |> Seq.contains model.PackageName) - |> Seq.map (fun model -> model.GetLibReferences(projectFile.GetTargetProfile())) - |> Seq.concat - |> Seq.groupBy (fun p -> FileInfo(p).Name) - |> Seq.choose(fun (_,librariesForPackage) -> - librariesForPackage - |> Seq.choose(fun library -> - try - let key = FileInfo(library).FullName.ToLowerInvariant() - let assembly = - match loadedLibs.TryGetValue key with - | true,v -> v - | _ -> - let v = Assembly.ReflectionOnlyLoadFrom library - loadedLibs.Add(key,v) - v - - 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) + + let assemblies = + extractedPackages + |> Seq.map snd + |> Seq.filter (fun model -> dependencies |> Seq.contains model.PackageName) + |> Seq.map (fun model -> model.GetLibReferences(projectFile.GetTargetProfile())) + |> Seq.concat + |> Seq.groupBy (fun p -> FileInfo(p).Name) + |> Seq.choose(fun (_,librariesForPackage) -> + librariesForPackage + |> Seq.choose(fun library -> + try + let key = FileInfo(library).FullName.ToLowerInvariant() + let assembly = + match loadedLibs.TryGetValue key with + | true,v -> v + | _ -> + let v = Assembly.ReflectionOnlyLoadFrom library + loadedLibs.Add(key,v) + v + + Some (assembly, BindingRedirects.getPublicKeyToken assembly) + with exn -> None) + |> Seq.sortBy(fun (assembly,_) -> assembly.GetName().Version) + |> Seq.toList + |> List.rev + |> function | head :: _ -> Some head | _ -> None) + |> Seq.cache + + assemblies + |> Seq.choose (fun (assembly,token) -> token |> Option.map (fun token -> (assembly,token))) + |> Seq.filter (fun (assembly,_) -> + assemblies + |> Seq.collect (fun (a,_) -> a.GetReferencedAssemblies()) + |> Seq.filter (fun a -> assembly.GetName().Name = a.Name) + |> Seq.exists (fun a -> assembly.GetName().Version > a.Version)) |> Seq.map(fun (assembly, token) -> { BindingRedirect.AssemblyName = assembly.GetName().Name Version = assembly.GetName().Version.ToString()