From cf9a92d64ebb7b289782fc9ce0598ebec8267434 Mon Sep 17 00:00:00 2001 From: Leonid Lapshin Date: Tue, 1 Sep 2020 15:53:26 +0300 Subject: [PATCH] add VS build tools installation, tests, reports, made minor changes to current VS install helper functions --- .../scripts/ImageHelpers/ImageHelpers.psm1 | 3 +- .../scripts/ImageHelpers/InstallHelpers.ps1 | 10 +---- .../ImageHelpers/VisualStudioHelpers.ps1 | 38 ++++++++++++++----- images/win/scripts/Installers/Install-VS.ps1 | 25 ++++++------ .../SoftwareReport.Generator.ps1 | 7 +++- .../SoftwareReport.VisualStudio.psm1 | 2 +- .../win/scripts/Tests/VisualStudio.Tests.ps1 | 16 +++++++- images/win/toolsets/toolset-2016.json | 3 ++ images/win/toolsets/toolset-2019.json | 3 ++ 9 files changed, 70 insertions(+), 37 deletions(-) diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index e150e1a12..9441ac7a2 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-VisualStudioInstallation' 'Get-VisualStudioComponents' ) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 282c03762..dc815eea7 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -266,14 +266,8 @@ function Get-VSExtensionVersion [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') + $instanceFolders = "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\" + (Get-VisualStudioInstallation -VSInstallType "VS").InstanceId + $stateContent = Get-Content -Path (Join-Path $instanceFolders '\state.packages.json') $state = $stateContent | ConvertFrom-Json $packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version diff --git a/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 b/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 index 0fd6bc8b6..bf87912de 100644 --- a/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1 @@ -61,20 +61,40 @@ Function Install-VisualStudio } function Get-VsCatalogJsonPath { - $instanceFolder = Get-Item "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*" | Select-Object -First 1 - return Join-Path $instanceFolder.FullName "catalog.json" + $instanceFolder = "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\" + (Get-VisualStudioInstallation -VSInstallType "VS").InstanceId + return Join-Path $instanceFolder "catalog.json" } -function Get-VisualStudioPath { - return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).InstallationPath -} +function Get-VisualStudioInstallation { + Param + ( + [Parameter(Mandatory)] + [String] $VSInstallType + ) -function Get-VisualStudioPackages { - return (Get-VSSetupInstance | Select-VSSetupInstance -Product *).Packages + if ($VSInstallType -eq "VS") + { + $VSSelectionType = "*Enterprise*" + } + elseif ($VSInstallType -eq "BuildTools") + { + $VSSelectionType = "*Build*" + } + else + { + Write-Output "Visual Studio Installation type have to be 'VS' or 'BuildTools'" + exit 1 + } + return Get-VSSetupInstance | Select-VSSetupInstance -Product * | Where-Object -Property DisplayName -like $VSSelectionType } function Get-VisualStudioComponents { - Get-VisualStudioPackages | Where-Object type -in 'Component', 'Workload' | + Param + ( + [Parameter(Mandatory)] + [String] $VSInstallType + ) + (Get-VisualStudioInstallation -VSInstallType $VSInstallType).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 +} diff --git a/images/win/scripts/Installers/Install-VS.ps1 b/images/win/scripts/Installers/Install-VS.ps1 index ed4fca73f..9d075ce4a 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 $_" } +$buildRequiredComponents = $toolset.visualStudio.build_workloads | ForEach-Object { "--add $_" } $workLoads = @( "--allWorkloads --includeRecommended" $requiredComponents "--remove Component.CPython3.x64" ) $workLoadsArgument = [String]::Join(" ", $workLoads) +$buildWorkLoads = @( + "--includeRecommended" + $buildRequiredComponents +) +$buildWorkLoadsArgument = [String]::Join(" ", $buildWorkLoads) $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-VisualStudioInstallation -VStype "VS").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..e818a25d8 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 -VSInstallType "VS") + (Get-VisualStudioExtensions)) | New-MDTable +$markdown += New-MDNewLine + +$markdown += New-MDHeader "Build Workloads and components:" -Level 4 +$markdown += New-MDNewLine +$markdown += (Get-VisualStudioComponents -VSInstallType "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..ba6907b35 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.VisualStudio.psm1 @@ -23,7 +23,7 @@ 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-VisualStudioInstallation -VSInstallType "VS").Packages | Where-Object {$_.Id -match 'WixToolset.VisualStudioExtension.Dev' -and $_.type -eq 'vsix'}).Version # WDK $wdkPackageVersion = Get-VSExtensionVersion -packageName 'Microsoft.Windows.DriverKit' diff --git a/images/win/scripts/Tests/VisualStudio.Tests.ps1 b/images/win/scripts/Tests/VisualStudio.Tests.ps1 index 142a9917e..14806a5a5 100644 --- a/images/win/scripts/Tests/VisualStudio.Tests.ps1 +++ b/images/win/scripts/Tests/VisualStudio.Tests.ps1 @@ -5,7 +5,7 @@ Describe "Visual Studio" { } It "Devenv.exe" { - $vsInstallRoot = Get-VisualStudioPath + $vsInstallRoot = (Get-VisualStudioInstallation -VStype "VS").InstallationPath $devenvexePath = "${vsInstallRoot}\Common7\IDE\devenv.exe" $devenvexePath | Should -Exist } @@ -15,7 +15,19 @@ Describe "Visual Studio" { $expectedComponents = Get-ToolsetContent | Select-Object -ExpandProperty visualStudio | Select-Object -ExpandProperty workloads $testCases = $expectedComponents | ForEach-Object { @{ComponentName = $_} } BeforeAll { - $installedComponents = Get-VisualStudioComponents | Select-Object -ExpandProperty Package + $installedComponents = Get-VisualStudioComponents -VSInstallType "VS" | Select-Object -ExpandProperty Package + } + + It "" -TestCases $testCases { + $installedComponents | Should -Contain $ComponentName + } + } + + Context "Visual Studio build components" { + $expectedComponents = Get-ToolsetContent | Select-Object -ExpandProperty visualStudio | Select-Object -ExpandProperty build_workloads + $testCases = $expectedComponents | ForEach-Object { @{ComponentName = $_} } + BeforeAll { + $installedComponents = Get-VisualStudioComponents -VSInstallType "Build" | Select-Object -ExpandProperty Package } It "" -TestCases $testCases { diff --git a/images/win/toolsets/toolset-2016.json b/images/win/toolsets/toolset-2016.json index f01e9473c..d9a5a3259 100644 --- a/images/win/toolsets/toolset-2016.json +++ b/images/win/toolsets/toolset-2016.json @@ -226,6 +226,9 @@ "Microsoft.VisualStudio.Component.VC.Runtimes.ARM64.Spectre", "Microsoft.VisualStudio.Component.Workflow", "Microsoft.VisualStudio.Workload.Office" + ], + "build_workloads": [ + "Microsoft.VisualStudio.Workload.WebBuildTools" ] } } diff --git a/images/win/toolsets/toolset-2019.json b/images/win/toolsets/toolset-2019.json index e29552df3..684579e21 100644 --- a/images/win/toolsets/toolset-2019.json +++ b/images/win/toolsets/toolset-2019.json @@ -257,6 +257,9 @@ "Microsoft.VisualStudio.Workload.VisualStudioExtension", "Component.MDD.Linux", "Component.MDD.Linux.GCC.arm" + ], + "build_workloads": [ + "Microsoft.VisualStudio.Workload.WebBuildTools" ] } }