Site icon Knarfalingus.net

VS Offline Installer Cleanup

I’ve been using the VS 2017 Offline installer for a while after reading about it here.  It works pretty well and I’ve dutifully run the layout command many times when VS has had a new update.  After a while though this folder layout grows to a significant size, especially since I also follow the layout approach on the VS preview.

After researching a bit I found the clean argument for Visual Studio setup, which can remove an older catalog.  The list of older catalogs are in the archive sub-folder of the layout folder.

So with a little experimentation, I came up with the Powershell script below.  This took my layout folder usage from 372 GB down to a mere 100 GB total for both VS and VS Preview combined.

# Cleanup.ps1
Function Clear-VSOfflineLayout
{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string]$layoutpath,
[Parameter(Mandatory)]
[string]$exepath
)
Clear-Host

Get-ChildItem -Directory $layoutpath\Archive `
| Sort-Object CreationTime `
| ForEach-Object `
{
$fn = "$layoutpath\Archive\" + $_.Name + "\Catalog.json"
Write-Host $_.CreationTime.ToString() $fn
if (Test-Path $fn -PathType Leaf)
{
$arg = "--layout $layoutpath --clean " + $fn + " --passive"
Start-Process "$exepath" -ArgumentList $arg -Wait
}
else
{
Write-Host "Catalog already removed: " $fn
}
}
}

To run the script, pass the path of your layout folder and the path to vs_setup.exe to the powershell function


PS D:\layout>. .\cleanup.ps1
PS D:\layout> Clear-VSOfflineLayout -layoutpath "D:\Layout\Vs2017_preview_offline" -exepath "D:\layout\vs_professional_preview.exe"

 

 

Exit mobile version