-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlnProjMacros.fs
More file actions
102 lines (91 loc) · 4.02 KB
/
SlnProjMacros.fs
File metadata and controls
102 lines (91 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace Macros
open System
open System.IO
module SlnProjMacros =
let private findUnder extension path =
Directory.EnumerateFiles(path, sprintf "*.%s" extension, SearchOption.AllDirectories)
let findSln searchRoot = findUnder "sln" searchRoot
let findConfigUnder searchRoot = findUnder "config" searchRoot
type ConfigType =
| PackageRef of version:string
| Config of newVersion:string*oldVersion:string
with
member x.ToDump() =
sprintf "%A" x
type Config = {Version:ConfigType; Name:string; Src:string; Raw:string}
open SlnProjMacros
open System.Xml.Linq
open System.Xml.XPath
open BReusable.StringHelpers
open BReusable.Xml
module PackageConfigs =
let private listFrom2nd (x,y) = x, y |> List.ofSeq
let getPackageConfigs slnDir =
findConfigUnder slnDir
|> Seq.filter(fun x -> Path.GetFileName x = "packages.config")
|> List.ofSeq
//let pConfigs = getPackageConfigs()
let readPConfig path =
XDocument.Load(uri=path)
|> fun x -> x.XPathSelectElements "//package"
// Package Config
let getSortedPackages targetFolder configs =
configs
|> Seq.map (fun x -> x |> after targetFolder |> before "packages.config" |> trim1 "\\", readPConfig x)
|> Seq.map (fun (path, x) ->
x |> Seq.map(fun x ->
let text = x |> string
let pId = x |> getAttributeVal "id" |> Option.getOrDefault String.Empty
{Src=path; Name=pId; Version=getAttributeVal "version" x |> Option.getOrDefault String.Empty |> PackageRef;Raw=text}
)
)
|> Seq.concat
|> Seq.sortByDescending(fun x -> x.Version)
|> Seq.groupBy(fun x -> x.Name)
|> Seq.map listFrom2nd
|> Seq.filter(fun (_,x) -> x.Length > 1 && x |> Seq.map (fun x -> x.Version) |> Seq.distinct |> Seq.length |> fun x -> x > 1)
|> Seq.sortBy (fun (x,_) -> x <> "FSharp.Core")
module AppWebConfigs =
//open System.Linq
open BReusable
let getAppConfigs slnDir =
slnDir
|> findConfigUnder
|> Seq.filter(fun x -> Path.GetFileName x |> String.equalsI "app.config" || Path.GetFileName x |> String.equalsI "web.config")
|> List.ofSeq
let readConfig path =
XDocument.Load(uri=path)
|> fun x -> x.Root.XPathSelectElement "runtime"
|> Option.ofObj
|> Option.map (XElement.GetElements1 "assemblyBinding" >> Seq.collect (XElement.GetElements1 "dependentAssembly") >> List.ofSeq)
let getSortedRedirects targetFolder configs =
configs
// eliminate items without binding redirects
|> Seq.choose(fun path ->
match readConfig path with
| Some [] -> None
| Some x -> Some(path,x)
| None -> None
)
|> Seq.collect (fun (path,x) ->
x
|> Seq.map(fun x ->
try
let elements = x.Elements() |> Seq.map string |> List.ofSeq |> Seq.ofList
let br = x |> XElement.GetElements1 "bindingRedirect" |> Seq.single
let nv = br |> getAttributeVal "newVersion" |> Option.getOrDefault String.Empty
let ov = br |> getAttributeVal "oldVersion" |> Option.getOrDefault String.Empty
let ct = ConfigType.Config(nv,ov)
{ Name= x |> XElement.GetElements1 "assemblyIdentity" |> Seq.single |> getAttributeVal "name" |> Option.getOrDefault String.Empty
Version= ct
Raw= elements |> delimit "\r\n"
Src=path |> after targetFolder |> before ".config" |> trim1 "\\"
}
with ex ->
ex.Data.Add("Path",path)
ex.Data.Add("Element",x)
reraise()
)
)
|> Seq.groupBy(fun x -> x.Name)
|> Seq.filter(fun (_, items) -> items |> Seq.map (fun x -> x.Version) |> Seq.distinct |> Seq.length |> fun x -> x > 1)