← all posts

Configuring a Chocolatey Install

Gordon Beeming
Gordon Beeming
On this page1 section

So yesterday I posted Pushing a new project to Chocolatey and I said I would create another post showing how to configure how the Chocolatey install runs and this is that post 😜.

#ChocolateyInstall.ps1

The first (only really) step to do this is creating a ChocolateyInstall.ps1 script. From looking at other packages I saw that there was a file like this in a tools folder so I created one for myself in my DotNet Pretty project

ChocolateyInstall.ps1 in Visual Studio Solution Explorer
ChocolateyInstall.ps1 file added to the tools folder in the DotNet Pretty project

and set the Build Action to Content and Copy to Output Directory to Copy Always

Properties for ChocolateyInstall.ps1
Properties for ChocolateyInstall.ps1 set to Content and Copy Always

The contents of the script was as below

ChocolateyInstall.ps1
[string]$ScriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent[string]$copyTo = "$([System.Environment]::GetFolderPath("mydocuments"))\Visual Studio 2013\Visualizers"[string]$mainAssemblyPath = "$ScriptDir\..\..\lib\net45\*.*"[string]$binDependenciesAssemblyPath = "$ScriptDir\..\binDependencies\*.*"if (!(Test-Path -LiteralPath $copyTo)){    New-Item -Path $copyTo -ItemType directory}Copy-Item -Path "$mainAssemblyPath" -Destination "$copyTo" -ForceCopy-Item -Path "$binDependenciesAssemblyPath" -Destination "$copyTo" -Force

Basically doing the exact same thing as what I was doing with the DEBUG post build event in the project settings

I checked that in (over a couple of commits because I didn't get it right the first time 😜). MyGet picked up the new commit and performed a build for me. Instead of waiting for my hourly push of packages to Chocolatey from MyGet I just pushed the package as I did in the previous post. I then ran the Chocolatey install for my package

Terminal
choco install dotnetpretty -pre

and then navigated to the Visualizers folder and my new assemblies were there 🙂

Visualizers folder with new assemblies
Visualizers folder showing newly copied assemblies after Chocolatey install
 

If you have any feedback or a better way to perform this install do let me know 😁

Gordon Beeming
Gordon Beeming

Father • Husband • Triathlete • SSW Solution Architect

Related posts