Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding redirects from target platform only #1070

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions src/Paket.Core/BindingRedirects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,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()
Expand Down Expand Up @@ -118,6 +105,32 @@ 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 ->
p.GetTargetProfile()
|> 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
Expand Down
49 changes: 25 additions & 24 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,31 @@ 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 (targetProfile : TargetProfile) =
extractedPackages
|> Seq.map (fun (package, model:InstallModel) -> model.GetLibReferences(targetProfile))
|> 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
Expand Down