Skip to content

Commit f9eb04d

Browse files
author
Matt
authored
Refactored vsix install and cleaned up build sampleset
1 parent 2e07f1b commit f9eb04d

5 files changed

Lines changed: 49 additions & 84 deletions

File tree

.github/scripts/Install-Vsix.ps1

Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,38 @@
11
<#
22
33
.SYNOPSIS
4-
Checks WDK vsix version and downloads and installs as necessary.
4+
Download and install the latest WDK VSIX.
55
66
#>
77

8-
[CmdletBinding()]
9-
param(
10-
[bool]$optimize = $false
11-
)
12-
13-
$root = Get-Location
14-
15-
# launch developer powershell
16-
Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
17-
Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*")
18-
cd $root
19-
20-
# Automatically resolve the latest amd64 VSIX
8+
# set uri by resolving amd64 vsix
219
$uri = "https://marketplace.visualstudio.com$((Invoke-WebRequest -Uri "https://marketplace.visualstudio.com/items?itemName=DriverDeveloperKits-WDK.WDKVsix").Links | Where-Object outerHTML -like '*(amd64)*' | select -expand href)"
2210

23-
# Set local version variable
24-
$version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value
25-
26-
# Set github environment variable for vsix version
27-
"SAMPLES_VSIX_VERSION=$version" | Out-File -FilePath "$env:GITHUB_ENV" -Append
28-
29-
function PrintWdkVsix {
30-
"WDK Vsix Version: $(ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name)"
11+
# set download version
12+
$uri_version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value
13+
14+
# set msbuild path
15+
$msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\")
16+
17+
# download vsix, expand, and store the downloaded version extracted from the extension manifest
18+
"Downloading WDK VSIX version: $uri_version..."
19+
Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip
20+
"Expanding WDK VSIX archive..."
21+
Expand-Archive ".\wdk.zip" .\
22+
"Extracting version from manifest..."
23+
$downloaded_version = ([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version
24+
"Downloaded WDK VSIX version: $downloaded_version"
25+
26+
# copy msbuild files, extension manifest, and check installed version from the extension manifest
27+
"Copying WDK extension files to build path..."
28+
cp (".\`$MSBuild\*", ".\extension.vsixmanifest") "$msbuild_path" -Recurse -Force
29+
"Extracting version from copied manifest..."
30+
$installed_version = ([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version
31+
"Installed WDK VSIX Version: $installed_version"
32+
if (-not ("$downloaded_version" -eq "$installed_version")) {
33+
"WDK VSIX installation failed due to version mismatch"
34+
exit 1
3135
}
3236

33-
function TestWdkVsix {
34-
Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version"
35-
}
36-
37-
# NOTE: The '$optimize' code path examines the '.vsixmanifest' when downloaded and then examines it again (in the 'MSBuild' directory) once
38-
# the necessary extension files are copied.
39-
if ($optimize) {
40-
$msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\")
41-
"---> Downloading vsix version: $version"
42-
Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip
43-
Expand-Archive ".\wdk.zip" .\
44-
"Downloaded VSIX Version: $(([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)"
45-
"<--- Download complete"
46-
"---> Configuring build environment..."
47-
cp ".\`$MSBuild\*" "$msbuild_path" -Recurse -Force
48-
cp ".\extension.vsixmanifest" "$msbuild_path"
49-
"Installed VSIX Version: $(([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)"
50-
"<--- Configuration complete"
51-
}
52-
else {
53-
"Getting installed WDK vsix..."
54-
PrintWdkVsix
55-
"Checking the WDK.vsix version installed..."
56-
if (-not (TestWdkVsix)) {
57-
"The correct WDK vsix is not installed."
58-
"Will attempt to download and install now..."
59-
Invoke-WebRequest -Uri "$uri" -OutFile wdk.vsix
60-
"Finished downloading."
61-
"Starting install process. This will take some time to complete..."
62-
Start-Process vsixinstaller -ArgumentList "/f /q /sp .\wdk.vsix" -wait
63-
"The install process has finished."
64-
"Checking the WDK.vsix version installed..."
65-
if (TestWdkVsix) {
66-
PrintWdkVsix
67-
"The WDK vsix version is OK"
68-
}
69-
else {
70-
"The WDK vsix install FAILED"
71-
Write-Host "`u{274C} wdk vsix install had an issue"
72-
Write-Error "the wdk vsix cannot be installed at this time"
73-
exit 1
74-
}
75-
}
76-
}
37+
# set github environment variable for vsix version
38+
"SAMPLES_VSIX_VERSION=$installed_version" | Out-File -FilePath "$env:GITHUB_ENV" -Append

.github/workflows/Code-Scanning.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
submodules: 'recursive'
3939

4040
- name: Install WDK VSIX
41-
run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true
41+
run: .\.github\scripts\Install-Vsix.ps1
4242

4343
- name: Install Nuget Packages
4444
run: nuget restore .\packages.config -PackagesDirectory .\packages\

.github/workflows/ci-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
submodules: 'recursive'
2424

2525
- name: Install WDK VSIX
26-
run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true
26+
run: .\.github\scripts\Install-Vsix.ps1
2727

2828
- name: Install Nuget Packages
2929
run: nuget restore .\packages.config -PackagesDirectory .\packages\

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
submodules: 'recursive'
2424

2525
- name: Install WDK VSIX
26-
run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true
26+
run: .\.github\scripts\Install-Vsix.ps1
2727

2828
- name: Install Nuget Packages
2929
run: nuget restore .\packages.config -PackagesDirectory .\packages\

Build-SampleSet.ps1

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ finally {
5555
#
5656
# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'.
5757
# Determine build number (used for exclusions based on build number). Five digits. Say, '22621'.
58+
# Determine NuGet package version (if applicable).
59+
# Determine WDK vsix version.
5860
#
5961
$build_environment=""
6062
$build_number=0
6163
$nuget_package_version=0
64+
$vsix_version=""
6265
#
63-
# In Github we build using Nuget only and source version from repo .\Env-Vars.ps1.
66+
# In Github we build using NuGet and get the version from packages and vsix version from env var set from the install vsix step.
6467
#
6568
if ($env:GITHUB_REPOSITORY) {
6669
$build_environment="GitHub"
6770
$nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value
6871
$build_number=$nuget_package_version.split('.')[2]
72+
$vsix_version = $env:SAMPLES_VSIX_VERSION
6973
}
7074
#
7175
# WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1.
@@ -102,7 +106,19 @@ else {
102106
Write-Error "Could not determine build environment."
103107
exit 1
104108
}
105-
109+
#
110+
# Get the vsix version from packages if not set
111+
if (-not $vsix_version) {
112+
$vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name
113+
if ($vsix_version) {
114+
$vsix_version = $vsix_version.split('=')[1]
115+
}
116+
else {
117+
Write-Error "No version of the WDK VSIX could be found. The WDK VSIX is not installed."
118+
exit 1
119+
}
120+
}
121+
#
106122
#
107123
# InfVerif_AdditionalOptions
108124
#
@@ -164,19 +180,6 @@ $jresult = @{
164180

165181
$SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count
166182

167-
# Find vsix version either from env variabel or from packages
168-
$vsix_version = $env:SAMPLES_VSIX_VERSION
169-
if (-not $vsix_version) {
170-
$vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name
171-
if ($vsix_version) {
172-
$vsix_version = $vsix_version.split('=')[1]
173-
}
174-
else {
175-
Write-Error "No version for the WDK VSIX could be found. The WDK VSIX is not installed."
176-
exit 1
177-
}
178-
}
179-
180183
Write-Output ("Build Environment: " + $build_environment)
181184
Write-Output ("Build Number: " + $build_number)
182185
if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) }

0 commit comments

Comments
 (0)