Skip to content

Instantly share code, notes, and snippets.

@heaths
Last active December 22, 2019 12:20
Show Gist options
  • Save heaths/1d0658c6903871e09b72395c9ab44db1 to your computer and use it in GitHub Desktop.
Save heaths/1d0658c6903871e09b72395c9ab44db1 to your computer and use it in GitHub Desktop.
Fix Visual Studio package cache issues
The MIT License (MIT)
Copyright (C) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#Requires -Version 3
# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
[string] $Id,
[Parameter(Mandatory = $true, Position = 1)]
[Version] $Version
)
$ErrorActionPreference = 'Stop'
# Install the VSSetup module if required.
if (-not (get-module -list VSSetup)) {
write-verbose 'Will install the VSSetup module'
# Make sure PackageManagement (formerly OneGet) is installed.
# It is installed by default with WMF 5.0 (comes with Windows 10).
if (-not (get-module -list PackageManagement)) {
throw 'Please install PackageManagement from http:#go.microsoft.com/fwlink/?LinkID=746217'
}
install-module VSSetup -scope CurrentUser -skippublishercheck -force
}
# Normalize the version.
$build = $Version.Build
if ($build -lt 0) {
$build = 0
}
$revision = $Version.Revision
if ($revision -lt 0) {
$revision = 0
}
$Version = new-object System.Version $Version.Major, $Version.Minor, $build, $revision
get-vssetupinstance -all | foreach-object {
write-verbose "Checking instance '$($_.InstanceId)'"
$package = $_.Packages | where-object { $_.Id -eq $Id -and $_.Version -eq $Version }
if ($package) {
throw "Cannot delete cached package '$Id' because instance '$($_.InstanceId)' still requires it"
}
}
get-childitem "$($env:ProgramData)\Microsoft\VisualStudio\Packages" -filter "$Id,version=$Version*" | foreach-object {
write-verbose "Deleting unreferenced package cache '$($_.FullName)'"
$_ | remove-item -force -Recurse
}
#Requires -Version 3
# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt in the project root for license information.
[CmdletBinding()]
param ()
$ErrorActionPreference = 'Stop'
# Install the VSSetup module if required.
if (-not (get-module -list VSSetup)) {
write-verbose 'Will install the VSSetup module'
# Make sure PackageManagement (formerly OneGet) is installed.
# It is installed by default with WMF 5.0 (comes with Windows 10).
if (-not (get-module -list PackageManagement)) {
throw 'Please install PackageManagement from http://go.microsoft.com/fwlink/?LinkID=746217'
}
install-module VSSetup -scope CurrentUser -skippublishercheck -force
}
get-vssetupinstance -all | where-object { -not ($_.State -band 'NoRebootRequired') } | foreach-object {
write-verbose "Resetting reboot state for instance '$($_.InstanceId)'"
remove-item "$($env:ProgramData)\Microsoft\VisualStudio\Packages\_Instances\$($_.InstanceId)\reboot.sem" -force -ea 'SilentlyContinue'
}
@Naamboon
Copy link

it is works. Soon to be done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment