Skip to content

Commit 77a4528

Browse files
authored
Improve version info, vsix installation, and update building locally documentation
2 parents 3327adf + f9eb04d commit 77a4528

7 files changed

Lines changed: 68 additions & 84 deletions

File tree

.github/scripts/Install-Vsix.ps1

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +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 (if necessary)
16-
if (-not $env:VSCMD_VER) {
17-
Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
18-
Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*")
19-
cd $root
8+
# set uri by resolving amd64 vsix
9+
$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)"
10+
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
2035
}
2136

22-
# source environment variables
23-
. .\Env-Vars.ps1
24-
25-
$version = $env:SAMPLES_VSIX_VERSION
26-
$uri = $env:SAMPLES_VSIX_URI
27-
28-
function PrintWdkVsix {
29-
$installed = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name
30-
"WDK Vsix Version: $installed"
31-
}
32-
33-
function TestWdkVsix {
34-
Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version"
35-
}
36-
37-
if ($optimize) {
38-
"---> Downloading vsix and configuring build environment..."
39-
Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip
40-
Expand-Archive ".\wdk.zip" .\
41-
cp ".\`$MSBuild\*" (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") -Recurse -Force
42-
"<--- Finished"
43-
}
44-
else {
45-
"Getting installed WDK vsix..."
46-
PrintWdkVsix
47-
"Checking the WDK.vsix version installed..."
48-
if (-not (TestWdkVsix)) {
49-
"The correct WDK vsix is not installed."
50-
"Will attempt to download and install now..."
51-
Invoke-WebRequest -Uri "$uri" -OutFile wdk.vsix
52-
"Finished downloading."
53-
"Starting install process. This will take some time to complete..."
54-
Start-Process vsixinstaller -ArgumentList "/f /q /sp .\wdk.vsix" -wait
55-
"The install process has finished."
56-
"Checking the WDK.vsix version installed..."
57-
if (TestWdkVsix) {
58-
PrintWdkVsix
59-
"The WDK vsix version is OK"
60-
}
61-
else {
62-
"The WDK vsix install FAILED"
63-
Write-Host "`u{274C} wdk vsix install had an issue"
64-
Write-Error "the wdk vsix cannot be installed at this time"
65-
exit 1
66-
}
67-
}
68-
}
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: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ param(
1010

1111
$root = Get-Location
1212

13-
# launch developer powershell (if necessary)
13+
# launch developer powershell (if necessary to prevent multiple developer sessions)
1414
if (-not $env:VSCMD_VER) {
1515
Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
1616
Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*")
1717
cd $root
1818
}
1919

20-
# source environment variables
21-
. .\Env-Vars.ps1
22-
2320
$ThrottleFactor = 5
2421
$LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
2522

@@ -56,26 +53,34 @@ finally {
5653
}
5754

5855
#
59-
# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. Only used to determine build number.
56+
# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'.
6057
# 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.
6160
#
6261
$build_environment=""
6362
$build_number=0
63+
$nuget_package_version=0
64+
$vsix_version=""
6465
#
65-
# 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.
6667
#
6768
if ($env:GITHUB_REPOSITORY) {
6869
$build_environment="GitHub"
69-
$build_number=$env:SAMPLES_BUILD_NUMBER
70+
$nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value
71+
$build_number=$nuget_package_version.split('.')[2]
72+
$vsix_version = $env:SAMPLES_VSIX_VERSION
7073
}
7174
#
7275
# WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1.
7376
#
74-
# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named .\packages.
77+
# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named '.\packages'.
78+
# Further, we need to test that the directory has been hydrated using '.\packages\*'.
7579
#
76-
elseif(Test-Path(".\packages")) {
80+
elseif(Test-Path(".\packages\*")) {
7781
$build_environment=("NuGet")
78-
$build_number=$env:SAMPLES_BUILD_NUMBER
82+
$nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value
83+
$build_number=$nuget_package_version.split('.')[2]
7984
}
8085
#
8186
# EWDK sets environment variable BuildLab. For example 'ni_release_svc_prod1.22621.2428'.
@@ -101,7 +106,19 @@ else {
101106
Write-Error "Could not determine build environment."
102107
exit 1
103108
}
104-
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+
#
105122
#
106123
# InfVerif_AdditionalOptions
107124
#
@@ -165,6 +182,8 @@ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count
165182

166183
Write-Output ("Build Environment: " + $build_environment)
167184
Write-Output ("Build Number: " + $build_number)
185+
if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) }
186+
Write-Output ("WDK VSIX Version: " + $vsix_version)
168187
Write-Output ("Samples: " + $sampleSet.Count)
169188
Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")")
170189
Write-Output ("Platforms: " + $Platforms.Count + " (" + $Platforms + ")")

Building-Locally.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ To build the Windows Driver Samples you need a "driver build environment". In e
7979

8080
### Option A: Use WDK NuGet Packages
8181
* See [Download the Windows Driver Kit (WDK)](https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) for instructions on how to install Visual Studio, but only complete "Step 1". You do not need to install the SDK or the WDK.
82-
* Install the Visual Studio Windows Driver Kit Extension (WDK.vsix). Open Visual Studio -> Extensions -> Manage Extensions... -> Online -> Visual Studio Market Place -> Windows Driver Kit -> 10.0.26100.0 -> Download
82+
* Install the Visual Studio Windows Driver Kit Extension (WDK.vsix).
83+
* Open Visual Studio -> Extensions -> Manage Extensions... -> Browse.
84+
* In the search bar type: `Windows Driver Kit`.
85+
* Find the `Microsoft` signed extension.
86+
* Click the Install button.
8387
* Launch a "Developer Command Prompt for VS 2022".
8488
* Restore WDK packages from feed :
8589

Env-Vars.ps1

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)