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 "-ForegroundColorGreenSet-ExecutionPolicyBypass-ScopeProcess-Force;[System.Net.ServicePointManager]::SecurityProtocol=[System.Net.ServicePointManager]::SecurityProtocol-bor3072;Invoke-Expression((New-ObjectSystem.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}else{Write-host"Chocolatey $isChocoInstalled is already installed"-ForegroundColorGreen}
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-vif(-not($isChocoInstalled)){Write-host"Chocolatey is not installed, installation begin now "-ForegroundColorGreenSet-ExecutionPolicyBypass-ScopeProcess-Force;[System.Net.ServicePointManager]::SecurityProtocol=[System.Net.ServicePointManager]::SecurityProtocol-bor3072;Invoke-Expression((New-ObjectSystem.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}else{Write-host"Chocolatey $isChocoInstalled is already installed"-ForegroundColorGreen}chocoinstallgit--version2.35.1.2-ychocoinstallnodejs-lts--version16.14.0-ychocoinstallvscode--version1.65.0-ychocoinstallazure-data-studio--version1.35.0-ychocoinstalldotnet-6.0-sdk--version6.0.200-ychocoinstallvisualstudio2022professional--version117.1.0.0-y# you should select the appropriate VS versionchocoinstallmicrosoft-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.
# Run this command in PowerShell as Admin.# Install choco utility$isChocoInstalled=choco-v# Download and install Chocolatey from provided install.ps1if(-not($isChocoInstalled)){Write-host"Chocolatey is not installed, installation begin now "-ForegroundColorGreenSet-ExecutionPolicyBypass-ScopeProcess-Force;[System.Net.ServicePointManager]::SecurityProtocol=[System.Net.ServicePointManager]::SecurityProtocol-bor3072;Invoke-Expression((New-ObjectSystem.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}else{Write-host"Chocolatey $isChocoInstalled is already installed"-ForegroundColorGreen}# Install git, node, vs code, visual studio, azure data studio, dotnet SDK, and windows terminalchocoinstallgitchocoinstallnodejs-ltschocoinstallvscodechocoinstallazure-data-studiochocoinstalldotnet-6.0-sdkchocoinstallvisualstudio2022professional--package-parameters"--add Microsoft.VisualStudio.Workload.CoreEditor --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetCoreTools --add Microsoft.VisualStudio.Workload.NetCrossPlat --add Microsoft.VisualStudio.Workload.NetWeb --passive --norestart --wait"chocoinstallmicrosoft-windows-terminal# install and configure oh-my-poshchocoinstalloh-my-poshAdd-Content-Path$PROFILE-Value'oh-my-posh --init --shell pwsh --config https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v$(oh-my-posh --version)/themes/marcduiker.omp.json | Invoke-Expression'# set git and npm proxy configurationgitconfig--globalhttp.proxyhttp://user:url_encoded_password@proxy.company.com:8000/npmconfigset proxyhttp://user:url_encoded_password@proxy.company.com:8000/
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: