Skip to content

Commit

Permalink
Generates binding redirect for references targeting different profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinaldi committed Apr 22, 2016
1 parent e4c924d commit 414613b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
5 changes: 3 additions & 2 deletions integrationtests/Paket.IntegrationTests/BindingRedirect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,16 @@ let ``#1477 assembly redirects lock files``() =
failwith "could not delete directory, i.e. restore holds on to files"

[<Test>]
[<Ignore("this is not part of paket behaviour right now")>]
let ``#1621 didn't generate binding redirect for projectB``() =
let ``#1621 generates binding redirect when references project with another target profile``() =
let scenario = "i001621-different-framework"
install scenario |> ignore
let ``NUnit`` = """<assemblyIdentity name="nunit.framework" publicKeyToken="2638cd05610744eb" culture="neutral" />"""
let ``NUnit correct version`` = "newVersion=\"3.0.5813.39031\""

let path = Path.Combine(scenarioTempPath scenario, "projectB")
let configPath = Path.Combine(path, "app.config")

let config = File.ReadAllText(configPath) |> normalizeLineEndings

config |> shouldContainText ``NUnit``
config |> shouldContainText ``NUnit correct version``
38 changes: 26 additions & 12 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ let private applyBindingRedirects isFirstGroup createNewBindingFiles cleanBindin
referenceFile.Groups
|> Seq.filter (fun g -> g.Key = groupName)
|> Seq.collect (fun g -> g.Value.NugetPackages |> List.map (fun p -> (groupName,p.Name)))
|> Seq.collect findDependencies)
|> Seq.collect findDependencies
|> Seq.map (fun x -> x, projectFile.GetTargetProfile()))
|> Set.ofSeq
| None -> Set.empty

Expand All @@ -235,33 +236,46 @@ let private applyBindingRedirects isFirstGroup createNewBindingFiles cleanBindin
let assemblies =
extractedPackages
|> Seq.map (fun (model,redirects) -> (model, redirectsFromReference model.PackageName |> Option.fold (fun _ x -> Some x) redirects))
|> Seq.filter (fun (model,_) -> dependencies |> Set.contains model.PackageName)
|> Seq.collect (fun (model,redirects) -> model.GetLibReferences targetProfile |> Seq.map (fun lib -> lib,redirects))
|> Seq.groupBy (fun (p,_) -> FileInfo(p).Name)
|> Seq.collect (fun (model,redirects) ->
dependencies
|> Set.filter (fst >> ((=) model.PackageName))
|> Seq.collect (fun (_,profile) ->
model.GetLibReferences profile
|> Seq.map (fun x -> x, redirects, profile)))
|> Seq.groupBy (fun (p,_,profile) -> profile,FileInfo(p).Name)
|> Seq.choose(fun (_,librariesForPackage) ->
librariesForPackage
|> Seq.choose(fun (library,redirects) ->
|> Seq.choose(fun (library,redirects,profile) ->
try
let assembly = LoadAssembliesSafe.reflectionOnlyLoadFrom library
Some (assembly, BindingRedirects.getPublicKeyToken assembly, assembly.GetReferencedAssemblies(), redirects)
Some (assembly, BindingRedirects.getPublicKeyToken assembly, assembly.GetReferencedAssemblies(), redirects, profile)
with _ -> None)
|> Seq.sortBy(fun (assembly,_,_,_) -> assembly.GetName().Version)
|> Seq.sortBy(fun (assembly,_,_,_,_) -> assembly.GetName().Version)
|> Seq.toList
|> List.rev
|> function | head :: _ -> Some head | _ -> None)
|> Seq.cache

let referencesDifferentProfiles (assemblyName : AssemblyName) profile =
profile = targetProfile
&& assemblies
|> Seq.filter (fun (_,_,_,_,p) -> p <> profile)
|> Seq.map (fun (a,_,_,_,_) -> a.GetName())
|> Seq.filter (fun a -> a.Name = assemblyName.Name)
|> Seq.exists (fun a -> a.Version <> assemblyName.Version)

assemblies
|> Seq.choose (fun (assembly,token,refs,redirects) -> token |> Option.map (fun token -> (assembly,token,refs,redirects)))
|> Seq.filter (fun (_,_,_,packageRedirects) -> defaultArg ((packageRedirects |> Option.map ((<>) Off)) ++ redirects) false)
|> Seq.filter (fun (assembly,_,_,redirects) ->
|> Seq.choose (fun (assembly,token,refs,redirects,profile) -> token |> Option.map (fun token -> (assembly,token,refs,redirects,profile)))
|> Seq.filter (fun (_,_,_,packageRedirects,_) -> defaultArg ((packageRedirects |> Option.map ((<>) Off)) ++ redirects) false)
|> Seq.filter (fun (assembly,_,_,redirects,profile) ->
let assemblyName = assembly.GetName()
redirects = Some Force
|| referencesDifferentProfiles assemblyName profile
|| assemblies
|> Seq.collect (fun (_,_,refs,_) -> refs)
|> Seq.collect (fun (_,_,refs,_,_) -> refs)
|> Seq.filter (fun a -> assemblyName.Name = a.Name)
|> Seq.exists (fun a -> assemblyName.Version > a.Version))
|> Seq.map(fun (assembly, token,_,_) ->
|> Seq.map(fun (assembly, token,_,_,_) ->
{ BindingRedirect.AssemblyName = assembly.GetName().Name
Version = assembly.GetName().Version.ToString()
PublicKeyToken = token
Expand Down

0 comments on commit 414613b

Please sign in to comment.