From 4a80096e71c3134eae4c36cc3cbf2d55f00fb92d Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Mon, 17 Feb 2020 14:19:30 +0300 Subject: [PATCH 1/7] swap WDK installation block --- images/win/Windows2019-Azure.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 46792679b..cb8648a2d 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -152,12 +152,6 @@ "{{ template_dir }}/scripts/Installers/Windows2019/Update-DockerImages.ps1" ] }, - { - "type": "powershell", - "scripts": [ - "{{ template_dir }}/scripts/Installers/Windows2019/Install-WDK.ps1" - ] - }, { "type": "powershell", "valid_exit_codes": [ @@ -186,6 +180,12 @@ "{{ template_dir }}/scripts/Installers/Install-NET48.ps1" ] }, + { + "type": "powershell", + "scripts": [ + "{{ template_dir }}/scripts/Installers/Windows2019/Install-WDK.ps1" + ] + }, { "type": "powershell", "scripts":[ From 3aeecf18ab9f06b710b58c3cfd1f2d64f8826593 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Tue, 18 Feb 2020 20:32:24 +0300 Subject: [PATCH 2/7] add WDK validation --- .../Installers/Windows2019/Install-WDK.ps1 | 15 ++++--- .../Installers/Windows2019/Validate-WDK.ps1 | 42 ++++++++++++++++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 b/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 index 205275e0b..5389870b8 100644 --- a/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 +++ b/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 @@ -3,10 +3,6 @@ ## Desc: Install the Windows Driver Kit ################################################################################ -# Version: 10.0.18362.0 -# Update Validate-WDK.ps1 if the version changes! -# There doesn't seem to be any way to check the version programmatically - # Requires Windows SDK with the same version number as the WDK $winSdkUrl = "https://go.microsoft.com/fwlink/p/?linkid=2083338" $wdkUrl = "https://go.microsoft.com/fwlink/?linkid=2085767" @@ -31,11 +27,20 @@ if ($wdkExitCode -ne 0) # Need to install the VSIX to get the build targets when running VSBuild # Write-Host "Installing WDK.vsix" - $process = Start-Process ` +try +{ + $process = Start-Process ` -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\VSIXInstaller.exe" ` -ArgumentList ("/quiet", '"C:\Program Files (x86)\Windows Kits\10\Vsix\VS2019\WDK.vsix"') ` -Wait ` -PassThru +} +catch +{ + Write-Host "There is an error during WDK.vsix installation" + $_ +} + $exitCode = $process.ExitCode diff --git a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 index db941621e..f1fe044d6 100644 --- a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 +++ b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 @@ -3,11 +3,51 @@ ## Desc: Validate the installation of the Windows Driver Kit ################################################################################ +function Get-WDKExtensionPackage { + $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 + } + + $stateContent = Get-Content -Path ($instanceFolders.FullName + '\state.packages.json') + $state = $stateContent | ConvertFrom-Json + $WDKPackageVersion = ($state.packages | where { $_.id -eq "Microsoft.Windows.DriverKit" }).version + + if (!$WDKPackageVersion) + { + Write-Host "WDK package for Visual studio was not found" + exit 1 + } + + return $WDKPackageVersion +} + +function Get-WDKVersion +{ + $WDKVersion = (Get-WmiObject Win32_Product -Filter "Name = 'Windows Driver Kit'").version + + if (!$WDK) + { + Write-Host "WDK was not found" + exit 1 + } + + return $WDKVersion +} + +$WDKVersion = Get-WDKVersion +$WDKPackageVersion = Get-WDKExtensionPackage + # Adding description of the software to Markdown $SoftwareName = "Windows Driver Kit" $Description = @" -_Version:_ 10.0.18362.0
+_WDK Version:_ $WDKVersion
+_WDK Visual Studio Extension Version:_ $WDKPackageVersion
"@ Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description From 7a8a434503827cda4895103a5990531bf8e2aeea Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Tue, 18 Feb 2020 22:33:31 +0300 Subject: [PATCH 3/7] fix variable name --- images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 index f1fe044d6..7d1a3bf0c 100644 --- a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 +++ b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 @@ -30,7 +30,7 @@ function Get-WDKVersion { $WDKVersion = (Get-WmiObject Win32_Product -Filter "Name = 'Windows Driver Kit'").version - if (!$WDK) + if (!$WDKVersion) { Write-Host "WDK was not found" exit 1 From 70df8fdded1674b655e770f90eea52e15a1e343d Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Wed, 19 Feb 2020 19:59:48 +0300 Subject: [PATCH 4/7] make VS19ExtensionVersion function --- .../scripts/ImageHelpers/ImageHelpers.psm1 | 1 + .../scripts/ImageHelpers/InstallHelpers.ps1 | 40 ++++++++++++++++--- .../Installers/Windows2019/Validate-WDK.ps1 | 25 +----------- .../Installers/Windows2019/Validate-Wix.ps1 | 29 +------------- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 index 6e091e7e7..ae58a9818 100644 --- a/images/win/scripts/ImageHelpers/ImageHelpers.psm1 +++ b/images/win/scripts/ImageHelpers/ImageHelpers.psm1 @@ -18,4 +18,5 @@ Export-ModuleMember -Function @( 'Add-SoftwareDetailsToMarkdown' 'Stop-SvcWithErrHandling' 'Set-SvcWithErrHandling' + 'Get-VS19ExtensionVersion' ) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 56fac941e..44cafa252 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -83,8 +83,8 @@ function Install-EXE } function Stop-SvcWithErrHandling -<# -.DESCRIPTION +<# +.DESCRIPTION Function for stopping the Windows Service with error handling .AUTHOR @@ -98,7 +98,7 @@ Switch for stopping the script and exit from PowerShell if one service is absent #> { param ( - [Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName, + [Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName, [Parameter()] [switch] $StopOnError ) @@ -126,8 +126,8 @@ Switch for stopping the script and exit from PowerShell if one service is absent } function Set-SvcWithErrHandling -<# -.DESCRIPTION +<# +.DESCRIPTION Function for setting the Windows Service parameter with error handling .AUTHOR @@ -140,7 +140,7 @@ The name of stopping service Hashtable for service arguments #> { - + param ( [Parameter(Mandatory, ValueFromPipeLine = $true)] [string] $ServiceName, [Parameter(Mandatory)] [hashtable] $Arguments @@ -160,3 +160,31 @@ Hashtable for service arguments } } } + +function Get-VS19ExtensionVersion +{ + param ( + [string] [Parameter(Mandatory=$true)] $packageName + ) + + $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 + } + + $stateContent = Get-Content -Path ($instanceFolders.FullName + '\state.packages.json') + $state = $stateContent | ConvertFrom-Json + $packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version + + if (!$packageVersion) + { + Write-Host "installed package $packageName for Visual Studio 2019 was not found" + exit 1 + } + + return $packageVersion +} diff --git a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 index 7d1a3bf0c..c3c6a8f04 100644 --- a/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 +++ b/images/win/scripts/Installers/Windows2019/Validate-WDK.ps1 @@ -3,28 +3,7 @@ ## Desc: Validate the installation of the Windows Driver Kit ################################################################################ -function Get-WDKExtensionPackage { - $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 - } - - $stateContent = Get-Content -Path ($instanceFolders.FullName + '\state.packages.json') - $state = $stateContent | ConvertFrom-Json - $WDKPackageVersion = ($state.packages | where { $_.id -eq "Microsoft.Windows.DriverKit" }).version - - if (!$WDKPackageVersion) - { - Write-Host "WDK package for Visual studio was not found" - exit 1 - } - - return $WDKPackageVersion -} +Import-Module -Name ImageHelpers -Force function Get-WDKVersion { @@ -40,7 +19,7 @@ function Get-WDKVersion } $WDKVersion = Get-WDKVersion -$WDKPackageVersion = Get-WDKExtensionPackage +$WDKPackageVersion = Get-VS19ExtensionVersion -packageName "Microsoft.Windows.DriverKit" # Adding description of the software to Markdown $SoftwareName = "Windows Driver Kit" diff --git a/images/win/scripts/Installers/Windows2019/Validate-Wix.ps1 b/images/win/scripts/Installers/Windows2019/Validate-Wix.ps1 index 94724a3de..4334beb14 100644 --- a/images/win/scripts/Installers/Windows2019/Validate-Wix.ps1 +++ b/images/win/scripts/Installers/Windows2019/Validate-Wix.ps1 @@ -11,23 +11,6 @@ function Get-WixVersion { return $Version } -#Gets the extension details from state.json -function Get-WixExtensionPackage { - $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 - } - - $stateContent = Get-Content -Path ($instanceFolders.FullName + '\state.packages.json') - $state = $stateContent | ConvertFrom-Json - $WixPackage = $state.packages | where { $_.id -eq "WixToolset.VisualStudioExtension.Dev16" } - return $WixPackage -} - $WixToolSetVersion = Get-WixVersion if($WixToolSetVersion) { @@ -38,22 +21,14 @@ else { exit 1 } -$WixPackage = Get-WixExtensionPackage - -if($WixPackage) { - Write-Host "Wix Extension version" $WixPackage.version "installed" -} -else { - Write-Host "Wix Extension is not installed" - exit 1 -} +$WixPackageVersion = Get-VS19ExtensionVersion -packageName "WixToolset.VisualStudioExtension.Dev16" # Adding description of the software to Markdown $SoftwareName = "WIX Tools" $Description = @" _Toolset Version:_ $WixToolSetVersion
-_WIX Toolset Visual Studio Extension Version:_ $($WixPackage.version)
+_WIX Toolset Visual Studio Extension Version:_ $WixPackageVersion
_Environment:_ * WIX: Installation root of WIX "@ From af94d525dfc22299f3b925ad18012d5b915ce175 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 20 Feb 2020 11:43:24 +0300 Subject: [PATCH 5/7] add exit1 to wdk vsix installation --- images/win/scripts/Installers/Windows2019/Install-WDK.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 b/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 index 5389870b8..b70644370 100644 --- a/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 +++ b/images/win/scripts/Installers/Windows2019/Install-WDK.ps1 @@ -39,6 +39,7 @@ catch { Write-Host "There is an error during WDK.vsix installation" $_ + exit 1 } From 5c221ffd9a5f2351dd183d96f3433f96288effff Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 20 Feb 2020 12:33:24 +0300 Subject: [PATCH 6/7] add missing space --- images/win/scripts/ImageHelpers/InstallHelpers.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 44cafa252..24b0b92e0 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -170,7 +170,7 @@ function Get-VS19ExtensionVersion $vsProgramData = Get-Item -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances" $instanceFolders = Get-ChildItem -Path $vsProgramData.FullName - if($instanceFolders -is [array]) + if ($instanceFolders -is [array]) { Write-Host "More than one instance installed" exit 1 From 9f3e6569438d6f5814b06c02fb3dc44eb36a5f38 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev Date: Thu, 20 Feb 2020 20:24:07 +0300 Subject: [PATCH 7/7] nitpicks --- images/win/scripts/ImageHelpers/InstallHelpers.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 24b0b92e0..6eec7e793 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -167,8 +167,7 @@ function Get-VS19ExtensionVersion [string] [Parameter(Mandatory=$true)] $packageName ) - $vsProgramData = Get-Item -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances" - $instanceFolders = Get-ChildItem -Path $vsProgramData.FullName + $instanceFolders = Get-ChildItem -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances" if ($instanceFolders -is [array]) { @@ -176,7 +175,7 @@ function Get-VS19ExtensionVersion exit 1 } - $stateContent = Get-Content -Path ($instanceFolders.FullName + '\state.packages.json') + $stateContent = Get-Content -Path (Join-Path $instanceFolders '\state.packages.json') $state = $stateContent | ConvertFrom-Json $packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version