diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index 07b406621..e150e1a12 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -35,7 +35,8 @@ Export-ModuleMember -Function @( 'Get-EnvironmentVariable' 'Invoke-PesterTests' 'Get-VsCatalogJsonPath' + 'Get-VisualStudioPath' 'Install-AndroidSDKPackages' - 'Get-VisualStudioProduct' + 'Get-VisualStudioPackages' 'Get-VisualStudioComponents' ) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 9f1a32f6a..282c03762 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -258,6 +258,34 @@ function Install-VsixExtension } } +function Get-VSExtensionVersion +{ + Param + ( + [Parameter(Mandatory=$true)] + [string] $packageName + ) + + $instanceFolders = Get-ChildItem -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances" + if ($instanceFolders -is [array]) + { + Write-Host "More than one instance installed" + exit 1 + } + + $stateContent = Get-Content -Path (Join-Path $instanceFolders.FullName '\state.packages.json') + $state = $stateContent | ConvertFrom-Json + $packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version + + if (-not $packageVersion) + { + Write-Host "installed package $packageName for Visual Studio 2019 was not found" + exit 1 + } + + return $packageVersion +} + function Get-ToolcachePackages { $toolcachePath = Join-Path $env:ROOT_FOLDER "toolcache.json" diff --git a/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 b/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 index d9478390f..0fd6bc8b6 100644 --- a/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 @@ -60,60 +60,21 @@ Function Install-VisualStudio } } -function Get-VisualStudioInstancePath { - return "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\" + (Get-VisualStudioProduct -ProductType "VisualStudio").InstanceId -} - function Get-VsCatalogJsonPath { - return Join-Path (Get-VisualStudioInstancePath) "catalog.json" + $instanceFolder = Get-Item "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*" | Select-Object -First 1 + return Join-Path $instanceFolder.FullName "catalog.json" } -function Get-VisualStudioProduct { - Param - ( - [Parameter(Mandatory)] - [ValidateSet('VisualStudio','BuildTools')] - [String] $ProductType - ) +function Get-VisualStudioPath { + return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).InstallationPath +} - if ($ProductType -eq "VisualStudio") - { - $VSSelectionType = "*Enterprise*" - } - elseif ($ProductType -eq "BuildTools") - { - $VSSelectionType = "*Build*" - } - return Get-VSSetupInstance | Where-Object -Property DisplayName -like $VSSelectionType +function Get-VisualStudioPackages { + return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).Packages } function Get-VisualStudioComponents { - Param - ( - [Parameter(Mandatory)] - [String] $ProductType - ) - (Get-VisualStudioProduct -ProductType $ProductType).Packages | Where-Object type -in 'Component', 'Workload' | + Get-VisualStudioPackages | Where-Object type -in 'Component', 'Workload' | Sort-Object Id, Version | Select-Object @{n = 'Package'; e = {$_.Id}}, Version | Where-Object { $_.Package -notmatch "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}" } -} - -function Get-VSExtensionVersion -{ - Param - ( - [Parameter(Mandatory=$true)] - [string] $PackageName - ) - - $state = Get-Content -Path (Join-Path (Get-VisualStudioInstancePath) '\state.packages.json') | ConvertFrom-Json - $packageVersion = ($state.packages | Where-Object { $_.id -eq $PackageName }).version - - if (-not $packageVersion) - { - Write-Host "installed package $PackageName for Visual Studio 2019 was not found" - exit 1 - } - - return $packageVersion -} +} \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-VS.ps1 b/images/win/scripts/Installers/Install-VS.ps1 index be776dded..ed4fca73f 100644 --- a/images/win/scripts/Installers/Install-VS.ps1 +++ b/images/win/scripts/Installers/Install-VS.ps1 @@ -1,35 +1,38 @@ ################################################################################ ## File: Install-VS.ps1 -## Desc: Install Visual Studio and build tools +## Desc: Install Visual Studio ################################################################################ $ErrorActionPreference = "Stop" $toolset = Get-ToolsetContent $requiredComponents = $toolset.visualStudio.workloads | ForEach-Object { "--add $_" } -$buildToolsRequiredComponents = $toolset.visualStudio.buildtools_workloads | ForEach-Object { "--add $_" } $workLoads = @( "--allWorkloads --includeRecommended" $requiredComponents "--remove Component.CPython3.x64" ) $workLoadsArgument = [String]::Join(" ", $workLoads) -$buildToolsWorkloads= @( - "--includeRecommended" - $buildToolsRequiredComponents -) -$buildWorkLoadsArgument = [String]::Join(" ", $buildToolsWorkloads) $releaseInPath = $toolset.visualStudio.edition $subVersion = $toolset.visualStudio.subversion $bootstrapperUrl = "https://aka.ms/vs/${subVersion}/release/vs_${releaseInPath}.exe" -$buildbootstrapperUrl = "https://aka.ms/vs/${subVersion}/release/vs_buildtools.exe" -# Install VS and VS Build tools +# Install VS Install-VisualStudio -BootstrapperUrl $bootstrapperUrl -WorkLoads $workLoadsArgument -Install-VisualStudio -BootstrapperUrl $buildbootstrapperUrl -WorkLoads $buildWorkLoadsArgument -$vsInstallRoot = (Get-VisualStudioProduct -ProductType "VisualStudio").InstallationPath +# Find the version of VS installed for this instance +# Only supports a single instance +$vsProgramData = Get-Item -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances" +$instanceFolders = Get-ChildItem -Path $vsProgramData.FullName + +if ($instanceFolders -is [array]) +{ + Write-Host "More than one instance installed" + exit 1 +} + +$vsInstallRoot = Get-VisualStudioPath # Initialize Visual Studio Experimental Instance & "$vsInstallRoot\Common7\IDE\devenv.exe" /RootSuffix Exp /ResetSettings General.vssettings /Command File.Exit diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index 5ff886c77..eb8b35f0d 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -171,12 +171,7 @@ $markdown += New-MDNewLine $markdown += New-MDHeader "Workloads, components and extensions:" -Level 4 $markdown += New-MDNewLine -$markdown += ((Get-VisualStudioComponents -ProductType "VisualStudio") + (Get-VisualStudioExtensions)) | New-MDTable -$markdown += New-MDNewLine - -$markdown += New-MDHeader "Build Tools Workloads:" -Level 4 -$markdown += New-MDNewLine -$markdown += (Get-VisualStudioComponents -ProductType "BuildTools") | New-MDTable +$markdown += ((Get-VisualStudioComponents) + (Get-VisualStudioExtensions)) | New-MDTable $markdown += New-MDNewLine $markdown += New-MDHeader "Microsoft Visual C++:" -Level 4 diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 index 9427ccc3b..0004c168b 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 @@ -23,18 +23,18 @@ function Get-VisualStudioExtensions { # Wix $vs = (Get-VisualStudioVersion).Name.Split()[-1] $wixPackageVersion = Get-WixVersion - $wixExtensionVersion = ((Get-VisualStudioProduct -ProductType "VisualStudio").Packages | Where-Object {$_.Id -match 'WixToolset.VisualStudioExtension.Dev' -and $_.type -eq 'vsix'}).Version + $wixExtensionVersion = (Get-VisualStudioPackages | Where-Object {$_.Id -match 'WixToolset.VisualStudioExtension.Dev' -and $_.type -eq 'vsix'}).Version # WDK - $wdkPackageVersion = Get-VSExtensionVersion -PackageName 'Microsoft.Windows.DriverKit' + $wdkPackageVersion = Get-VSExtensionVersion -packageName 'Microsoft.Windows.DriverKit' $wdkExtensionVersion = Get-WDKVersion # SSDT - $analysisPackageVersion = Get-VSExtensionVersion -PackageName '04a86fc2-dbd5-4222-848e-911638e487fe' - $reportingPackageVersion = Get-VSExtensionVersion -PackageName '717ad572-c4b7-435c-c166-c2969777f718' + $analysisPackageVersion = Get-VSExtensionVersion -packageName '04a86fc2-dbd5-4222-848e-911638e487fe' + $reportingPackageVersion = Get-VSExtensionVersion -packageName '717ad572-c4b7-435c-c166-c2969777f718' $integrationPackageName = ($vs -match "2019") ? '851E7A09-7B2B-4F06-A15D-BABFCB26B970' : 'D1B09713-C12E-43CC-9EF4-6562298285AB' - $integrationPackageVersion = Get-VSExtensionVersion -PackageName $integrationPackageName + $integrationPackageVersion = Get-VSExtensionVersion -packageName $integrationPackageName $extensions = @( @{Package = 'SSDT Microsoft Analysis Services Projects'; Version = $analysisPackageVersion} diff --git a/images/win/scripts/Tests/SSDTExtensions.Tests.ps1 b/images/win/scripts/Tests/SSDTExtensions.Tests.ps1 index 5b6031de5..7d1c6ee0b 100644 --- a/images/win/scripts/Tests/SSDTExtensions.Tests.ps1 +++ b/images/win/scripts/Tests/SSDTExtensions.Tests.ps1 @@ -9,12 +9,12 @@ Describe "SSDTExtensions" { ) It "Extensions id=" -TestCases $testExtenions { - $version = Get-VSExtensionVersion -PackageName "${id}" + $version = Get-VSExtensionVersion -packageName "${id}" $version | Should -Not -BeNullOrEmpty } } else { It "Extension SSDT" { - $version = Get-VSExtensionVersion -PackageName "SSDT" + $version = Get-VSExtensionVersion -packageName "SSDT" $version | Should -Not -BeNullOrEmpty } } diff --git a/images/win/scripts/Tests/VisualStudio.Tests.ps1 b/images/win/scripts/Tests/VisualStudio.Tests.ps1 index 56869cc91..142a9917e 100644 --- a/images/win/scripts/Tests/VisualStudio.Tests.ps1 +++ b/images/win/scripts/Tests/VisualStudio.Tests.ps1 @@ -5,27 +5,17 @@ Describe "Visual Studio" { } It "Devenv.exe" { - $vsInstallRoot = (Get-VisualStudioProduct -ProductType "VisualStudio").InstallationPath + $vsInstallRoot = Get-VisualStudioPath $devenvexePath = "${vsInstallRoot}\Common7\IDE\devenv.exe" $devenvexePath | Should -Exist } } Context "Visual Studio components" { - $testCases = (Get-ToolsetContent).visualStudio.workloads | ForEach-Object { @{ComponentName = $_} } + $expectedComponents = Get-ToolsetContent | Select-Object -ExpandProperty visualStudio | Select-Object -ExpandProperty workloads + $testCases = $expectedComponents | ForEach-Object { @{ComponentName = $_} } BeforeAll { - $installedComponents = Get-VisualStudioComponents -ProductType "VisualStudio" | Select-Object -ExpandProperty Package - } - - It "" -TestCases $testCases { - $installedComponents | Should -Contain $ComponentName - } - } - - Context "Visual Studio Build Tools components" { - $testCases = (Get-ToolsetContent).visualStudio.buildtools_workloads | ForEach-Object { @{ComponentName = $_} } - BeforeAll { - $installedComponents = Get-VisualStudioComponents -ProductType "BuildTools" | Select-Object -ExpandProperty Package + $installedComponents = Get-VisualStudioComponents | Select-Object -ExpandProperty Package } It "" -TestCases $testCases { diff --git a/images/win/scripts/Tests/WDK.Tests.ps1 b/images/win/scripts/Tests/WDK.Tests.ps1 index 0f8e76770..c67586e79 100644 --- a/images/win/scripts/Tests/WDK.Tests.ps1 +++ b/images/win/scripts/Tests/WDK.Tests.ps1 @@ -5,7 +5,7 @@ Describe "WDK" { } It "WDK version from system" { - $version = Get-VSExtensionVersion -PackageName "Microsoft.Windows.DriverKit" + $version = Get-VSExtensionVersion -packageName "Microsoft.Windows.DriverKit" $version | Should -Not -BeNullOrEmpty } } diff --git a/images/win/scripts/Tests/Wix.Tests.ps1 b/images/win/scripts/Tests/Wix.Tests.ps1 index bd22bef36..2a12261e2 100644 --- a/images/win/scripts/Tests/Wix.Tests.ps1 +++ b/images/win/scripts/Tests/Wix.Tests.ps1 @@ -12,11 +12,11 @@ Describe "Wix" { It "Wix Toolset version from system" { if (Test-IsWin19) { - $exVersion = Get-VSExtensionVersion -PackageName "WixToolset.VisualStudioExtension.Dev16" + $exVersion = Get-VSExtensionVersion -packageName "WixToolset.VisualStudioExtension.Dev16" } else { - $exVersion = Get-VSExtensionVersion -PackageName "WixToolset.VisualStudioExtension.Dev15" + $exVersion = Get-VSExtensionVersion -packageName "WixToolset.VisualStudioExtension.Dev15" } $exVersion | Should -Not -BeNullOrEmpty } diff --git a/images/win/toolsets/toolset-2016.json b/images/win/toolsets/toolset-2016.json index c292c7af9..a76246e60 100644 --- a/images/win/toolsets/toolset-2016.json +++ b/images/win/toolsets/toolset-2016.json @@ -227,9 +227,6 @@ "Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre", "Microsoft.VisualStudio.Component.Workflow", "Microsoft.VisualStudio.Workload.Office" - ], - "buildtools_workloads": [ - "Microsoft.VisualStudio.Workload.WebBuildTools" ] } } diff --git a/images/win/toolsets/toolset-2019.json b/images/win/toolsets/toolset-2019.json index db7919f9a..a2a7ec4a5 100644 --- a/images/win/toolsets/toolset-2019.json +++ b/images/win/toolsets/toolset-2019.json @@ -259,9 +259,6 @@ "Microsoft.VisualStudio.Workload.VisualStudioExtension", "Component.MDD.Linux", "Component.MDD.Linux.GCC.arm" - ], - "buildtools_workloads": [ - "Microsoft.VisualStudio.Workload.WebBuildTools" ] } }