|
1 | 1 | <# |
2 | 2 |
|
3 | 3 | .SYNOPSIS |
4 | | -Checks WDK vsix version and downloads and installs as necessary. |
| 4 | +Download and install the latest WDK VSIX. |
5 | 5 |
|
6 | 6 | #> |
7 | 7 |
|
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 |
21 | 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)" |
22 | 10 |
|
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 |
31 | 35 | } |
32 | 36 |
|
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 |
0 commit comments