Using Chocolatey
Chocolatey is software management automation for Windows that wraps installers, executables, zips, and scripts into compiled packages.
Namespace
To be used, the Choco
module needs the Fake.Windows
namespace:
#r "paket:
nuget Fake.Windows.Chocolatey //"
open Fake.Windows
Install
The Install
method allow to easily install packages from Chocolatey.
By default all user interaction are skipped but it can be modified through the NonInteractive
property.
"BuildApp" =?> ("InspectCodeAnalysis", Choco.IsAvailable)
Target.create "InspectCodeAnalysis" (fun _ ->
"resharper-clt.portable" |> Choco.install id
...
)
Pack
The Pack
and PackFromTemplate
methods allow to pack a .nuspec, chocolateyInstall.ps1 and/or chocolateyUninstall.ps1 file to a package (.nupkg).
It is based on NuGet
but have some specifics, the package can be base on templates for the .nuspec, the chocolateyInstall.ps1 and/or chocolateyUninstall.ps1 but it's not mandatory.
It is also possible to only defines the fields in ChocoPackParams and the corresponding files will be created.
Target.create "ChocoPack" (fun _ ->
Choco.pack (fun p ->
{ p with
PackageId = "nvika"
Version = version
Title = "NVika"
Authors = ["laedit"]
Owners = ["laedit"]
ProjectUrl = "https://github.com/laedit/vika"
IconUrl = "https://cdn.rawgit.com/laedit/vika/master/icon.png"
LicenseUrl = "https://github.com/laedit/vika/blob/master/LICENSE"
BugTrackerUrl = "https://github.com/laedit/vika/issues"
Description = "Parse analysis reports (InspectCode, ...) and send messages to build server or console."
Tags = ["report"; "parsing"; "build"; "server"; "inspectcode"]
ReleaseNotes = "https://github.com/laedit/vika/releases"
PackageDownloadUrl = "https://github.com/laedit/vika/releases/download/" + tag + "/NVika." + version + ".zip"
Checksum = Checksum.CalculateFileHash ("NVika." + version + ".zip")
ChecksumType = Choco.ChocolateyChecksumType.Sha256
})
)
Nuspec
It adds Chocolatey specific fields:
Placeholder |
replaced by ( |
---|---|
|
|
|
|
|
|
|
|
|
|
chocolateyInstall.ps1
To use a chocolateyInstall.ps1 template, a file with the same name must exists in a tool
folder alongside the .nuspec template file.
If it doesn't exists but at least Title
and PackageDownloadUrl
are defined, the chocolateyInstall.ps1 will be created
Placeholder |
replaced by ( |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chocolateyUninstall.ps1
To use a chocolateyUninstall.ps1 template, a file with the same name must exists in a tool
folder alongside the .nuspec template file.
If it doesn't exists but at least Title
and UninstallPath
are defined, the chocolateyUninstall.ps1 will be created
Placeholder |
replaced by ( |
---|---|
|
|
|
|
|
|
|
|
Push
The Push
method allow to push a package (.nupkg) to Chocolatey.
If need the source could be modified to a private feed for example.
It is heavily recommended to indicate your Chocolatey api key, specifically for the build servers which don't have registered Chocolatey api key.
In order to keep it secret you can encrypt it, for example with |AppVeyor](https://www.appveyor.com) you can encrypt an environment variable and use it in your FAKE script:
Target.create "ChocoPush" (fun _ ->
"pretzel.0.5.0.nupkg" |> Choco.push (fun p -> { p with ApiKey = environVar myChocolateyApiKey })
)