diff --git a/chocolatey-visualstudio.extension/CHANGELOG.md b/chocolatey-visualstudio.extension/CHANGELOG.md index 315beaf7..c5ddc183 100644 --- a/chocolatey-visualstudio.extension/CHANGELOG.md +++ b/chocolatey-visualstudio.extension/CHANGELOG.md @@ -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. diff --git a/chocolatey-visualstudio.extension/chocolatey-visualstudio.extension.nuspec b/chocolatey-visualstudio.extension/chocolatey-visualstudio.extension.nuspec index 125f9709..be219d67 100644 --- a/chocolatey-visualstudio.extension/chocolatey-visualstudio.extension.nuspec +++ b/chocolatey-visualstudio.extension/chocolatey-visualstudio.extension.nuspec @@ -3,9 +3,9 @@ chocolatey-visualstudio.extension - 1.3.0 + 1.4.0 https://github.com/jberezanski/ChocolateyPackages/tree/master/chocolatey-visualstudio.extension - Jakub Bereżański + jberezanski Chocolatey Visual Studio servicing extensions Jakub Bereżański https://github.com/jberezanski/ChocolateyPackages/tree/master/chocolatey-visualstudio.extension diff --git a/chocolatey-visualstudio.extension/extensions/Get-VSProductReference.ps1 b/chocolatey-visualstudio.extension/extensions/Get-VSProductReference.ps1 new file mode 100644 index 00000000..99f9d210 --- /dev/null +++ b/chocolatey-visualstudio.extension/extensions/Get-VSProductReference.ps1 @@ -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 +} diff --git a/chocolatey-visualstudio.extension/extensions/Install-VisualStudio.ps1 b/chocolatey-visualstudio.extension/extensions/Install-VisualStudio.ps1 index 0978ce95..7198d792 100644 --- a/chocolatey-visualstudio.extension/extensions/Install-VisualStudio.ps1 +++ b/chocolatey-visualstudio.extension/extensions/Install-VisualStudio.ps1 @@ -37,7 +37,9 @@ 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) { @@ -45,21 +47,31 @@ Install-ChocolateyPackage $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 diff --git a/chocolatey-visualstudio.extension/extensions/Remove-VisualStudioProduct.ps1 b/chocolatey-visualstudio.extension/extensions/Remove-VisualStudioProduct.ps1 index 3e5ad811..0ed513ec 100644 --- a/chocolatey-visualstudio.extension/extensions/Remove-VisualStudioProduct.ps1 +++ b/chocolatey-visualstudio.extension/extensions/Remove-VisualStudioProduct.ps1 @@ -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." + } }