5 people like it.

Automatic install of Nuget with a script

When versioning a solution, I like to just version the packages.config and not the binaries themselves. that means upon checkout, one has to install the referenced Nugets. This is the purpose of this script. [For some reason you have to press 'enter' between commands..]

 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: 
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif

open System
open System.IO
open System.Xml.Linq
open System.Text.RegularExpressions

let rec findsolutiondir (p:DirectoryInfo) = 
      if (p.GetFiles("*.sln") |> Array.length > 0) 
      then p
      else findsolutiondir p.Parent


let root = findsolutiondir (DirectoryInfo(__SOURCE_DIRECTORY__))

let getprojectsdir (root:DirectoryInfo) = 
   let rec getdirs (root:DirectoryInfo) = seq {
      yield! root.GetDirectories() |> Array.filter(fun f -> f.GetFiles("*.fsproj") |> Array.length > 0 ) 
      yield! root.GetDirectories() |> Array.map(fun d -> getdirs d) |> Seq.concat}
   getdirs root   


   
getprojectsdir root |> Seq.iter (fun d ->    let p = new System.Diagnostics.Process();
                                             printfn "installing %A"d.Name
                                             p.StartInfo.WorkingDirectory <- root.FullName
                                             p.StartInfo.FileName <- "powershell.exe";
                                             p.StartInfo.Arguments <- ("/c nuget i " + d.Name + "\\packages.config -o Packages")
                                             p.StartInfo.RedirectStandardOutput <- true
                                             p.StartInfo.UseShellExecute <- false
                                             p.Start() |> ignore
                                             printfn "result ?"
                                             printfn "result %A" (p.StandardOutput.ReadToEnd())
                                             printfn "done"
                                 )
namespace System
namespace System.IO
namespace System.Xml
namespace System.Xml.Linq
namespace System.Text
namespace System.Text.RegularExpressions
val findsolutiondir : p:DirectoryInfo -> DirectoryInfo

Full name: Script.findsolutiondir
val p : 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 Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val length : array:'T [] -> int

Full name: Microsoft.FSharp.Collections.Array.length
property DirectoryInfo.Parent: DirectoryInfo
val root : DirectoryInfo

Full name: Script.root
val getprojectsdir : root:DirectoryInfo -> seq<DirectoryInfo>

Full name: Script.getprojectsdir
val root : DirectoryInfo
val getdirs : (DirectoryInfo -> seq<DirectoryInfo>)
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
DirectoryInfo.GetDirectories() : DirectoryInfo []
DirectoryInfo.GetDirectories(searchPattern: string) : DirectoryInfo []
DirectoryInfo.GetDirectories(searchPattern: string, searchOption: SearchOption) : DirectoryInfo []
val filter : predicate:('T -> bool) -> array:'T [] -> 'T []

Full name: Microsoft.FSharp.Collections.Array.filter
val f : DirectoryInfo
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
val d : DirectoryInfo
module Seq

from Microsoft.FSharp.Collections
val concat : sources:seq<#seq<'T>> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.concat
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
val p : Diagnostics.Process
namespace System.Diagnostics
Multiple items
type Process =
  inherit Component
  new : unit -> Process
  member BasePriority : int
  member BeginErrorReadLine : unit -> unit
  member BeginOutputReadLine : unit -> unit
  member CancelErrorRead : unit -> unit
  member CancelOutputRead : unit -> unit
  member Close : unit -> unit
  member CloseMainWindow : unit -> bool
  member EnableRaisingEvents : bool with get, set
  member ExitCode : int
  ...

Full name: System.Diagnostics.Process

--------------------
Diagnostics.Process() : unit
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
property DirectoryInfo.Name: string
property Diagnostics.Process.StartInfo: Diagnostics.ProcessStartInfo
property Diagnostics.ProcessStartInfo.WorkingDirectory: string
property FileSystemInfo.FullName: string
property Diagnostics.ProcessStartInfo.FileName: string
property Diagnostics.ProcessStartInfo.Arguments: string
property Diagnostics.ProcessStartInfo.RedirectStandardOutput: bool
property Diagnostics.ProcessStartInfo.UseShellExecute: bool
Diagnostics.Process.Start() : bool
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
property Diagnostics.Process.StandardOutput: StreamReader
StreamReader.ReadToEnd() : string
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/dp
Posted:12 years ago
Author:Nicolas2
Tags: script , nuget , git , deploy