First post of 2022 in March? Sorry for that, it took a while to get traction this year.
I have a habit of “starting over” with my development environment once a year at a minimum. That means that I reinstall the OS from scratch and all my tools. This is actually fun and not hard to do at all, but can it be automated? Yes, powershell + chocolatey is a good answer to this.
The goal of this post is very simple. Demonstrate how to setup a .NET / Node developer environment on Windows from scratch.
Chocolatey provides a convenient install.ps1 that you can download and install from powershell directly. Note that we check whether chocolatey is already installed before trying to install it again.
1
2
3
4
5
6
7
8
9
10
11
12
# Run this command in PowerShell as Admin.$isChocoInstalled = choco -v
# Download and install Chocolatey from provided install.ps1if (-not($isChocoInstalled)) {
Write-host "Chocolatey is not installed, installation begin now " -ForegroundColor Green
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor3072;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
} else {
Write-host "Chocolatey $isChocoInstalled is already installed" -ForegroundColor Green
}
packages available at chocolotey are not always officially supported. Use at your own risk.
To be honest I had written this post very long with step-by-step instructions. However, nearly everything can be achieved by the script below. Why complicate it?
Note that you can define the version to install. If you’d rather just install latest version available, remove the version parameter.
Another important thing to notice is that you may pass parameters to the visual studio 2022 professional package. See the list of parameters at VS Docs;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Run this command in PowerShell as Admin.$isChocoInstalled = choco -v
if (-not($isChocoInstalled)) {
Write-host "Chocolatey is not installed, installation begin now " -ForegroundColor Green
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor3072;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
} else {
Write-host "Chocolatey $isChocoInstalled is already installed" -ForegroundColor Green
}
choco install git --version 2.35.1.2 -y
choco install nodejs-lts --version 16.14.0 -y
choco install vscode --version 1.65.0 -y
choco install azure-data-studio --version 1.35.0 -y
choco install dotnet-6.0-sdk --version 6.0.200 -y
choco install visualstudio2022professional --version 117.1.0.0 -y # you should select the appropriate VS versionchoco install microsoft-windows-terminal
The following script represents my typical environment. Your needs may vary so it is a good idea to browse Chocolatey for other packages that are more applicable to you.
This approach works well if you have a reasonably stable environment. That is, you don’t hop between very different solutions too often. If you do change scopes often, a hosted environment might be a better choice for you. That is a subject for another post, but you can get started by checking the solutions below: