Installing the Cascadia Code Font
Fonts, like color schemes in general, are a very personal thing. Some people love the comic sans font, for example, while others loathe it. Some love dark themes, and others don’t. For programming, including PowerShell (with the console, VS Code, and possibly even Notepad), fixed-width fonts are easier to use. But the choice of which font is always a personal preference.
As part of the Visual Studio Code launch, Microsoft also created a new and free font that you can download and use at the PowerShell 7 console and inside VS Code. This recipe shows how you can download the font, install it, and set this font to be the default in VS Code.
This recipe shows how to install the Cascadia Code font, but you can choose many great fonts. See this article on (arguably!) the ten best fonts for use with VS Code: https://toastofcode.com/best-fonts-for-programming-with-vscode/.
And should you want to use a different font for VS Code, you can adapt this recipe to make use of whatever font you wish. Or use the VS Code settings menus to change the font as you may want.
How to do it...
- Getting download locations
$CascadiaRelURL = 'https://github.com/microsoft/cascadia-code/releases' $CascadiaRelease = Invoke-WebRequest -Uri $CascadiaRelURL $Fileleaf = ($CascadiaRelease.Links.href | Where-Object { $_ -match $CascadiaFont } | Select-Object -First 1) $CascadiaPath = 'https://github.com' + $FileLeaf $CascadiaFile = 'C:\Foo\CascadiaFontDL.zip'
- Downloading the Cascadia Code font file archive
Invoke-WebRequest -Uri $CascadiaPath -OutFile $CascadiaFile
- Expanding the font archive file
$FontFolder = 'C:\Foo\CascadiaCode' Expand-Archive -Path $CascadiaFile -DestinationPath $FontFolder
- Installing the Cascadia Code font
$FontFile = 'c:\Foo\CascadiaCode\ttf\CascadiaCode.ttf' $FontShellApp = New-Object -Com Shell.Application $FontShellNamespace = $FontShellApp.Namespace(0x14) $FontShellNamespace.CopyHere($FontFile, 0x10)
How it works...
In step 1, you determine the location of the latest release of the font and set a variable to the location to download the font.
In step 2, you use Invoke-WebRequest
to download the font archive. Then in step 3, you use Expand-Archive
to expand the archive. Finally, in step 4, you install the Cascadia font.
The steps in this recipe produce no console output – but you can see the change in VS Code after you run these steps.
There’s more...
In step 1, you determine the location of the latest release of the Cascadia Code font on GitHub. The font is heavily used and has been subject to minor updates and improvements over time. This step ensures you get the latest version. The remaining steps expand the downloaded archive and then install the font. Once you complete this recipe, you should observe the font inside VS Code.
In step 2, you download the latest version of the font – but as a ZIP archive, which, in step 3, you expand and then install (in step 4).