add VS build tools installation, tests, reports, made minor changes to current VS install helper functions

This commit is contained in:
Leonid Lapshin
2020-09-01 15:53:26 +03:00
parent dd518dff50
commit cf9a92d64e
9 changed files with 70 additions and 37 deletions

View File

@@ -35,8 +35,7 @@ Export-ModuleMember -Function @(
'Get-EnvironmentVariable'
'Invoke-PesterTests'
'Get-VsCatalogJsonPath'
'Get-VisualStudioPath'
'Install-AndroidSDKPackages'
'Get-VisualStudioPackages'
'Get-VisualStudioInstallation'
'Get-VisualStudioComponents'
)

View File

@@ -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

View File

@@ -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}" }
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -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 "<ComponentName>" -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 "<ComponentName>" -TestCases $testCases {

View File

@@ -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"
]
}
}

View File

@@ -257,6 +257,9 @@
"Microsoft.VisualStudio.Workload.VisualStudioExtension",
"Component.MDD.Linux",
"Component.MDD.Linux.GCC.arm"
],
"build_workloads": [
"Microsoft.VisualStudio.Workload.WebBuildTools"
]
}
}