1 people like it.

Print Conflicting Assembly References

Print conflicting .NET assembly references (https://gist.github.com/brianlow/1553265 ported to an F# script)

 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: 
open System.IO
open System.Reflection

type Reference =
    { Assembly: AssemblyName
      ReferencedAssembly: AssemblyName }

let assemblies path =
    let d = DirectoryInfo(path)
    [| yield! d.GetFiles("*.dll", SearchOption.AllDirectories)
       yield! d.GetFiles("*.exe", SearchOption.AllDirectories) |]
    |> Array.map (fun f -> Assembly.LoadFile(f.FullName))

let references (assemblies: Assembly array) =
    [| for a in assemblies do
           for r in a.GetReferencedAssemblies() do
               yield { Assembly = a.GetName(); ReferencedAssembly = r } |]

let conflicts (references: Reference array) =
    references
    |> Array.groupBy (fun r -> r.ReferencedAssembly.Name)
    |> Array.filter (fun (_,rs) -> 
        rs 
        |> Array.distinctBy (fun r -> r.ReferencedAssembly.FullName) 
        |> Array.length > 1)

let printConflicts path =
    assemblies path
    |> references
    |> conflicts
    |> Array.iter (fun (n,rs) ->
        printfn "Possible conflicts for %s" n
        rs 
        |> Array.iter (fun r -> 
            printfn "%s references %s"
                (r.Assembly.Name.PadRight(25)) 
                r.ReferencedAssembly.FullName))
namespace System
namespace System.IO
namespace System.Reflection
type Reference =
  {Assembly: AssemblyName;
   ReferencedAssembly: AssemblyName;}

Full name: Script.Reference
Multiple items
Reference.Assembly: AssemblyName

--------------------
type Assembly =
  member CodeBase : string
  member CreateInstance : typeName:string -> obj + 2 overloads
  member EntryPoint : MethodInfo
  member Equals : o:obj -> bool
  member EscapedCodeBase : string
  member Evidence : Evidence
  member FullName : string
  member GetCustomAttributes : inherit:bool -> obj[] + 1 overload
  member GetCustomAttributesData : unit -> IList<CustomAttributeData>
  member GetExportedTypes : unit -> Type[]
  ...

Full name: System.Reflection.Assembly
Multiple items
type AssemblyName =
  new : unit -> AssemblyName + 1 overload
  member Clone : unit -> obj
  member CodeBase : string with get, set
  member CultureInfo : CultureInfo with get, set
  member EscapedCodeBase : string
  member Flags : AssemblyNameFlags with get, set
  member FullName : string
  member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
  member GetPublicKey : unit -> byte[]
  member GetPublicKeyToken : unit -> byte[]
  ...

Full name: System.Reflection.AssemblyName

--------------------
AssemblyName() : unit
AssemblyName(assemblyName: string) : unit
Reference.ReferencedAssembly: AssemblyName
val assemblies : path:string -> Assembly []

Full name: Script.assemblies
val path : string
val d : DirectoryInfo
Multiple items
type DirectoryInfo =
  inherit FileSystemInfo
  new : path:string -> DirectoryInfo
  member Create : unit -> unit + 1 overload
  member CreateSubdirectory : path:string -> DirectoryInfo + 1 overload
  member Delete : unit -> unit + 1 overload
  member EnumerateDirectories : unit -> IEnumerable<DirectoryInfo> + 2 overloads
  member EnumerateFileSystemInfos : unit -> IEnumerable<FileSystemInfo> + 2 overloads
  member EnumerateFiles : unit -> IEnumerable<FileInfo> + 2 overloads
  member Exists : bool
  member GetAccessControl : unit -> DirectorySecurity + 1 overload
  member GetDirectories : unit -> DirectoryInfo[] + 2 overloads
  ...

Full name: System.IO.DirectoryInfo

--------------------
DirectoryInfo(path: string) : unit
DirectoryInfo.GetFiles() : FileInfo []
DirectoryInfo.GetFiles(searchPattern: string) : FileInfo []
DirectoryInfo.GetFiles(searchPattern: string, searchOption: SearchOption) : FileInfo []
type SearchOption =
  | TopDirectoryOnly = 0
  | AllDirectories = 1

Full name: System.IO.SearchOption
field SearchOption.AllDirectories = 1
module Array

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val f : FileInfo
type Assembly =
  member CodeBase : string
  member CreateInstance : typeName:string -> obj + 2 overloads
  member EntryPoint : MethodInfo
  member Equals : o:obj -> bool
  member EscapedCodeBase : string
  member Evidence : Evidence
  member FullName : string
  member GetCustomAttributes : inherit:bool -> obj[] + 1 overload
  member GetCustomAttributesData : unit -> IList<CustomAttributeData>
  member GetExportedTypes : unit -> Type[]
  ...

Full name: System.Reflection.Assembly
Assembly.LoadFile(path: string) : Assembly
property FileSystemInfo.FullName: string
val references : assemblies:Assembly array -> Reference []

Full name: Script.references
val assemblies : Assembly array
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>
val a : Assembly
val r : AssemblyName
Assembly.GetReferencedAssemblies() : AssemblyName []
Assembly.GetName() : AssemblyName
Assembly.GetName(copiedName: bool) : AssemblyName
val conflicts : references:Reference array -> ('a * 'b) []

Full name: Script.conflicts
val references : Reference array
val filter : predicate:('T -> bool) -> array:'T [] -> 'T []

Full name: Microsoft.FSharp.Collections.Array.filter
val rs : 'b
val length : array:'T [] -> int

Full name: Microsoft.FSharp.Collections.Array.length
val printConflicts : path:string -> unit

Full name: Script.printConflicts
val iter : action:('T -> unit) -> array:'T [] -> unit

Full name: Microsoft.FSharp.Collections.Array.iter
val n : string
val rs : Reference []
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val r : Reference
Reference.Assembly: AssemblyName
property AssemblyName.Name: string
System.String.PadRight(totalWidth: int) : string
System.String.PadRight(totalWidth: int, paddingChar: char) : string
property AssemblyName.FullName: string
Raw view Test code New version

More information

Link:http://fssnip.net/tB
Posted:8 years ago
Author:Simon Cousins
Tags: assembly , references