Skip to content

Commit

Permalink
chocolatey-visualstudio.extension: improve reliability
Browse files Browse the repository at this point in the history
- skip VS 2017 product installation if the product is already installed
  (prevents upgrade, but also avoids problems with upgrade, such as
  broken VS Installer or installation still running after Chocolatey
  exits) (#7, #8)
- warn the user to disallow running the Chocolatey Auto Uninstaller (#6)
  • Loading branch information
jberezanski committed Jun 5, 2017
1 parent 567f7af commit ac32f2a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
5 changes: 5 additions & 0 deletions chocolatey-visualstudio.extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Version 1.4.0

- Install-VisualStudio can detect existing Visual Studio 2017 products and skip the installation (an interim solution before upgrading is implemented).
- Remove-VisualStudioProduct warns the user not to allow the Chocolatey Auto Uninstaller to run.

## Version 1.3.0

- New helper: Get-VisualStudioInstance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>chocolatey-visualstudio.extension</id>
<version>1.3.0</version>
<version>1.4.0</version>
<packageSourceUrl>https://github.com/jberezanski/ChocolateyPackages/tree/master/chocolatey-visualstudio.extension</packageSourceUrl>
<owners>Jakub Bereżański</owners>
<owners>jberezanski</owners>
<title>Chocolatey Visual Studio servicing extensions</title>
<authors>Jakub Bereżański</authors>
<projectUrl>https://github.com/jberezanski/ChocolateyPackages/tree/master/chocolatey-visualstudio.extension</projectUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Get-VSProductReference
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)] [string] $VisualStudioYear,
[Parameter(Mandatory = $true)] [string] $Product
)

switch ($VisualStudioYear)
{
'2017' { $channelId = 'VisualStudio.15.Release' }
default { throw "Unsupported VisualStudioYear: $VisualStudioYear"}
}

$productId = "Microsoft.VisualStudio.Product." + $Product

$props = @{
ChannelId = $channelId
ProductId = $productId
}

$obj = New-Object -TypeName PSObject -Property $props
return $obj
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,41 @@ Install-ChocolateyPackage
[string] $Checksum,
[string] $ChecksumType,
[ValidateSet('MsiVS2015OrEarlier', 'WillowVS2017OrLater')] [string] $InstallerTechnology,
[string] $ProgramsAndFeaturesDisplayName = $ApplicationName
[string] $ProgramsAndFeaturesDisplayName = $ApplicationName,
[string] $VisualStudioYear,
[string] $Product
)
if ($Env:ChocolateyPackageDebug -ne $null)
{
$VerbosePreference = 'Continue'
$DebugPreference = 'Continue'
Write-Warning "VerbosePreference and DebugPreference set to Continue due to the presence of ChocolateyPackageDebug environment variable"
}
Write-Debug "Running 'Install-VisualStudio' for $PackageName with ApplicationName:'$ApplicationName' Url:'$Url' Checksum:$Checksum ChecksumType:$ChecksumType InstallerTechnology:'$InstallerTechnology' ProgramsAndFeaturesDisplayName:'$ProgramsAndFeaturesDisplayName'";
Write-Debug "Running 'Install-VisualStudio' for $PackageName with ApplicationName:'$ApplicationName' Url:'$Url' Checksum:$Checksum ChecksumType:$ChecksumType InstallerTechnology:'$InstallerTechnology' ProgramsAndFeaturesDisplayName:'$ProgramsAndFeaturesDisplayName' ChannelId:'$ChannelId' ProductId:'$ProductId'";

$assumeNewVS2017Installer = $InstallerTechnology -eq 'WillowVS2017OrLater'

$uninstallKey = Get-VSUninstallRegistryKey -ApplicationName $ProgramsAndFeaturesDisplayName
$count = ($uninstallKey | Measure-Object).Count
if ($count -gt 0)
if ($assumeNewVS2017Installer)
{
if ($assumeNewVS2017Installer)
# there is a single Programs and Features entry for all products, so its presence is not enough
if ($VisualStudioYear -ne '' -and $Product -ne '')
{
# TODO: implement detection of products installed by Willow
# (there is a single Programs and Features entry for all products, so its presence is not enough)
Write-Debug "Programs and Features entry '$ProgramsAndFeaturesDisplayName' detected, this or other product from this family is installed"
$prodRef = Get-VSProductReference -VisualStudioYear $VisualStudioYear -Product $Product
$products = Get-WillowInstalledProducts | Where-Object { $_ -ne $null -and $_.channelId -eq $prodRef.ChannelId -and $_.productId -eq $prodRef.ProductId }
$productsCount = ($products | Measure-Object).Count
Write-Verbose ("Found {0} installed Visual Studio product(s) with ChannelId = {1} and ProductId = {2}" -f $productsCount, $prodRef.ChannelId, $prodRef.ProductId)
if ($productsCount -gt 0)
{
Write-Warning "$ApplicationName is already installed. Please use the Visual Studio Installer to modify or repair it."
return
}
}
else
}
else
{
$uninstallKey = Get-VSUninstallRegistryKey -ApplicationName $ProgramsAndFeaturesDisplayName
$count = ($uninstallKey | Measure-Object).Count
if ($count -gt 0)
{
Write-Warning "$ApplicationName is already installed. Please use Programs and Features in the Control Panel to modify or repair it."
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@

Write-Debug "Running 'Remove-VisualStudioProduct' with PackageName:'$PackageName' Product:'$Product' VisualStudioYear:'$VisualStudioYear'";
Start-VisualStudioModifyOperation -PackageName $PackageName -ArgumentList @() -VisualStudioYear $VisualStudioYear -ApplicableProducts @($Product) -OperationTexts @('uninstalled', 'uninstalling', 'uninstallation') -Operation 'uninstall'
$remainingProductsCount = (Get-WillowInstalledProducts | Measure-Object).Count
Write-Verbose ("Found {0} installed Visual Studio 2017 or later product(s)" -f $remainingProductsCount)
if ($remainingProductsCount -gt 0)
{
Write-Warning "If Chocolatey asks permission to run the Auto Uninstaller, please answer No! Otherwise, you might lose other Visual Studio products installed on your machine."
}
}

0 comments on commit ac32f2a

Please sign in to comment.