diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index e150e1a12..07b406621 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -35,8 +35,7 @@ Export-ModuleMember -Function @( 'Get-EnvironmentVariable' 'Invoke-PesterTests' 'Get-VsCatalogJsonPath' - 'Get-VisualStudioPath' 'Install-AndroidSDKPackages' - 'Get-VisualStudioPackages' + 'Get-VisualStudioProduct' 'Get-VisualStudioComponents' ) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 282c03762..9f1a32f6a 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -258,34 +258,6 @@ 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 0fd6bc8b6..d9478390f 100644 --- a/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 @@ -60,21 +60,60 @@ Function Install-VisualStudio } } +function Get-VisualStudioInstancePath { + return "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\" + (Get-VisualStudioProduct -ProductType "VisualStudio").InstanceId +} + function Get-VsCatalogJsonPath { - $instanceFolder = Get-Item "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*" | Select-Object -First 1 - return Join-Path $instanceFolder.FullName "catalog.json" + return Join-Path (Get-VisualStudioInstancePath) "catalog.json" } -function Get-VisualStudioPath { - return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).InstallationPath -} +function Get-VisualStudioProduct { + Param + ( + [Parameter(Mandatory)] + [ValidateSet('VisualStudio','BuildTools')] + [String] $ProductType + ) -function Get-VisualStudioPackages { - return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).Packages + if ($ProductType -eq "VisualStudio") + { + $VSSelectionType = "*Enterprise*" + } + elseif ($ProductType -eq "BuildTools") + { + $VSSelectionType = "*Build*" + } + return Get-VSSetupInstance | Where-Object -Property DisplayName -like $VSSelectionType } function Get-VisualStudioComponents { - Get-VisualStudioPackages | Where-Object type -in 'Component', 'Workload' | + Param + ( + [Parameter(Mandatory)] + [String] $ProductType + ) + (Get-VisualStudioProduct -ProductType $ProductType).Packages | 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}" } -} \ No newline at end of file +} + +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 +} diff --git a/images/win/scripts/Installers/Install-VS.ps1 b/images/win/scripts/Installers/Install-VS.ps1 index ed4fca73f..be776dded 100644 --- a/images/win/scripts/Installers/Install-VS.ps1 +++ b/images/win/scripts/Installers/Install-VS.ps1 @@ -1,38 +1,35 @@ ################################################################################ ## File: Install-VS.ps1 -## Desc: Install Visual Studio +## Desc: Install Visual Studio and build tools ################################################################################ $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 +# Install VS and VS Build tools Install-VisualStudio -BootstrapperUrl $bootstrapperUrl -WorkLoads $workLoadsArgument +Install-VisualStudio -BootstrapperUrl $buildbootstrapperUrl -WorkLoads $buildWorkLoadsArgument -# 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 +$vsInstallRoot = (Get-VisualStudioProduct -ProductType "VisualStudio").InstallationPath # 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 eb8b35f0d..5ff886c77 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -171,7 +171,12 @@ $markdown += New-MDNewLine $markdown += New-MDHeader "Workloads, components and extensions:" -Level 4 $markdown += New-MDNewLine -$markdown += ((Get-VisualStudioComponents) + (Get-VisualStudioExtensions)) | New-MDTable +$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 += 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 0004c168b..9427ccc3b 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-VisualStudioPackages | Where-Object {$_.Id -match 'WixToolset.VisualStudioExtension.Dev' -and $_.type -eq 'vsix'}).Version + $wixExtensionVersion = ((Get-VisualStudioProduct -ProductType "VisualStudio").Packages | 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 7d1c6ee0b..5b6031de5 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 142a9917e..56869cc91 100644 --- a/images/win/scripts/Tests/VisualStudio.Tests.ps1 +++ b/images/win/scripts/Tests/VisualStudio.Tests.ps1 @@ -5,17 +5,27 @@ Describe "Visual Studio" { } It "Devenv.exe" { - $vsInstallRoot = Get-VisualStudioPath + $vsInstallRoot = (Get-VisualStudioProduct -ProductType "VisualStudio").InstallationPath $devenvexePath = "${vsInstallRoot}\Common7\IDE\devenv.exe" $devenvexePath | Should -Exist } } Context "Visual Studio components" { - $expectedComponents = Get-ToolsetContent | Select-Object -ExpandProperty visualStudio | Select-Object -ExpandProperty workloads - $testCases = $expectedComponents | ForEach-Object { @{ComponentName = $_} } + $testCases = (Get-ToolsetContent).visualStudio.workloads | ForEach-Object { @{ComponentName = $_} } BeforeAll { - $installedComponents = Get-VisualStudioComponents | Select-Object -ExpandProperty Package + $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 } It "" -TestCases $testCases { diff --git a/images/win/scripts/Tests/WDK.Tests.ps1 b/images/win/scripts/Tests/WDK.Tests.ps1 index c67586e79..0f8e76770 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 2a12261e2..bd22bef36 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 a76246e60..c292c7af9 100644 --- a/images/win/toolsets/toolset-2016.json +++ b/images/win/toolsets/toolset-2016.json @@ -227,6 +227,9 @@ "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 a2a7ec4a5..db7919f9a 100644 --- a/images/win/toolsets/toolset-2019.json +++ b/images/win/toolsets/toolset-2019.json @@ -259,6 +259,9 @@ "Microsoft.VisualStudio.Workload.VisualStudioExtension", "Component.MDD.Linux", "Component.MDD.Linux.GCC.arm" + ], + "buildtools_workloads": [ + "Microsoft.VisualStudio.Workload.WebBuildTools" ] } }