/
Update.fs
108 lines (89 loc) · 3.91 KB
/
Update.fs
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
102
103
104
105
106
107
108
namespace Fake.DotNet.NuGet
/// <summary>
/// Contains tasks for updating NuGet packages including assembly hint paths in the project files using
/// the <a href="https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-update">nuget.exe update command</a>.
/// </summary>
module Update =
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.DotNet.NuGet.NuGet
open Fake.Core
open System
open Fake.DotNet.NuGet.Restore
/// <summary>
/// Nuget update parameters.
/// </summary>
[<CLIMutable>]
type NugetUpdateParams =
{
/// Path to the nuget.exe.
ToolPath: string
/// Timeout for the update.
TimeOut: TimeSpan
/// Number of retries if update fails.
Retries: int
/// Nuget feeds to search updates in. Use default if empty.
Sources: string list
/// Packages to update. Update all if empty.
Ids: string list
/// Version to update to. Default <c>None</c>. Used to upgrade/downgrade to a explicit version of a package.
Version: string option
/// Folder to store packages in. Default <c>./packages</c>.
RepositoryPath: string
/// Looks for updates with the highest version available within the same major and minor version as
/// the installed package. Default <c>false</c>.
Safe: bool
/// Show verbose output while updating. Default <c>false</c>.
Verbose: bool
/// Allows updating to prerelease versions. Default <c>false</c>.
Prerelease: bool
/// Do not prompt for user input or confirmations. Default <c>true</c>.
NonInteractive: bool
/// NuGet configuration file. Default <c>None</c>.
ConfigFile: string option
}
/// Parameter default values.
let NugetUpdateDefaults =
{ ToolPath = findNuget (Shell.pwd () @@ "tools" @@ "NuGet")
TimeOut = TimeSpan.FromMinutes 5.
Retries = 5
Sources = []
Ids = []
Version = None
RepositoryPath = "./packages"
Safe = false
Verbose = false
Prerelease = false
NonInteractive = true
ConfigFile = None }
/// [omit]
let buildArgs (param: NugetUpdateParams) =
[ param.Sources |> argList "source"
param.Ids |> argList "id"
[ param.RepositoryPath ] |> argList "repositoryPath"
param.Version |> Option.toList |> argList "Version"
(if param.Safe then "-safe" else "")
(if param.Prerelease then "-prerelease" else "")
(if param.NonInteractive then "-nonInteractive" else "")
(if param.Verbose then "-verbose" else "")
param.ConfigFile |> Option.toList |> argList "configFile" ]
|> Seq.filter (not << String.IsNullOrEmpty)
|> String.concat " "
/// <summary>
/// Update packages specified in the package file.
/// </summary>
/// <remarks>
/// Fails if packages are not installed; see <a href="https://nuget.codeplex.com/workitem/3874">nuget bug</a>.
/// Fails if packages file has no corresponding VS project; see
/// <a href="https://nuget.codeplex.com/workitem/3875">nuget bug</a>.
/// </remarks>
///
/// <param name="setParams">Function used to manipulate the default parameters.</param>
/// <param name="packagesFile">Path to the <c>*.sln</c>, <c>*.*proj</c> or <c>packages.config</c> file.</param>
let NugetUpdate setParams packagesFile =
use __ = Trace.traceTask "NugetUpdate" packagesFile
let param = NugetUpdateDefaults |> setParams
let args = sprintf "update %s %s" packagesFile (buildArgs param)
runNuGetTrial param.Retries param.ToolPath param.TimeOut args (fun () ->
failwithf "Package update for %s failed." packagesFile)
__.MarkSuccess()