Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions launcher/tiny11options.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@
<!-- Microsoft.Web.WebView2 brings Core + Wpf managed wrappers + the
native WebView2Loader.dll runtime asset. NuGet handles all three;
MSBuild copies WebView2Loader.dll to the output dir automatically
via the package's build/native targets. Pinned to the exact same
version (1.0.2535.41) that was previously vendored under
dependencies/webview2/. Bumping is a routine Dependabot PR. -->
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2535.41" />
via the package's build/native targets. This <PackageReference> is the
SINGLE SOURCE OF TRUTH for the WebView2 version: src/Tiny11.WebView2.psm1
resolves the SDK path from it (Get-Tiny11WebView2Version), so a routine
Dependabot bump flows through with no second edit. -->
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4078.44" />
<PackageReference Include="Velopack" Version="1.2.0" />
</ItemGroup>

Expand Down
30 changes: 25 additions & 5 deletions src/Tiny11.WebView2.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Set-StrictMode -Version Latest

$PinnedVersion = '1.0.2535.41'

# Minimum sizes must match the XAML MinWidth/MinHeight below; clamping prevents loading a
# stale settings.json from a previous build whose minimums were smaller.
$script:MinWindowWidth = 1000
Expand Down Expand Up @@ -33,18 +31,40 @@ function Save-Tiny11UserSettings {
[System.IO.File]::WriteAllText($path, $json, [System.Text.UTF8Encoding]::new($false))
}

function Get-Tiny11WebView2Version {
# The launcher csproj's <PackageReference> is the single source of truth for the
# WebView2 version. Reading it here (instead of hardcoding a copy) means a routine
# Dependabot bump to the csproj flows through automatically -- the SDK-path
# resolution below follows it with no second edit, so the two never drift.
[CmdletBinding()]
param([string]$CsprojPath)
if (-not $CsprojPath) {
$CsprojPath = Join-Path $PSScriptRoot '..\launcher\tiny11options.Launcher.csproj'
}
if (-not (Test-Path $CsprojPath)) {
throw "Cannot resolve the WebView2 version: launcher csproj not found at $CsprojPath."
}
$content = Get-Content -Path $CsprojPath -Raw
if ($content -match '<PackageReference\s+Include="Microsoft\.Web\.WebView2"\s+Version="([^"]+)"') {
return $Matches[1]
}
throw "Cannot resolve the WebView2 version: no Microsoft.Web.WebView2 <PackageReference> in $CsprojPath."
}

function Get-Tiny11WebView2SdkPath {
[CmdletBinding()]
param([string]$NugetPackagesRoot)
param([string]$NugetPackagesRoot, [string]$Version)
# Resolve the NuGet global packages folder. NUGET_PACKAGES env var overrides
# the default per Microsoft's NuGet docs on global-packages-and-cache-folders.
if (-not $NugetPackagesRoot) {
$NugetPackagesRoot = if ($env:NUGET_PACKAGES) { $env:NUGET_PACKAGES } else { Join-Path $env:USERPROFILE '.nuget\packages' }
}
# Version tracks the csproj (single source of truth) unless the caller overrides it.
if (-not $Version) { $Version = Get-Tiny11WebView2Version }
# NuGet caches as <root>\<id-lowercased>\<version>\... -- package id is lowercased on disk.
# Managed wrappers live under lib\<tfm>\; net462 is the right TFM for PowerShell 5.1
# (.NET Framework 4.x WPF host). Native loader lives under runtimes\win-x64\native\.
$pkgDir = Join-Path $NugetPackagesRoot "microsoft.web.webview2\$PinnedVersion"
$pkgDir = Join-Path $NugetPackagesRoot "microsoft.web.webview2\$Version"
[pscustomobject]@{
VersionDir = $pkgDir
CoreDll = Join-Path $pkgDir 'lib\net462\Microsoft.Web.WebView2.Core.dll'
Expand Down Expand Up @@ -193,4 +213,4 @@ function Show-Tiny11Wizard {
[void]$window.ShowDialog()
}

Export-ModuleMember -Function Get-Tiny11WebView2SdkPath, Test-Tiny11WebView2SdkPresent, Test-Tiny11WebView2RuntimeInstalled, Show-Tiny11Wizard, Set-Tiny11WizardWindow, Get-Tiny11WizardWindow, Get-Tiny11WizardWebView, Get-Tiny11UserSettingsPath, Get-Tiny11UserSettings, Save-Tiny11UserSettings
Export-ModuleMember -Function Get-Tiny11WebView2Version, Get-Tiny11WebView2SdkPath, Test-Tiny11WebView2SdkPresent, Test-Tiny11WebView2RuntimeInstalled, Show-Tiny11Wizard, Set-Tiny11WizardWindow, Get-Tiny11WizardWindow, Get-Tiny11WizardWebView, Get-Tiny11UserSettingsPath, Get-Tiny11UserSettings, Save-Tiny11UserSettings
49 changes: 43 additions & 6 deletions tests/Tiny11.WebView2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,52 @@ Set-StrictMode -Version 3.0
Import-Module "$PSScriptRoot/Tiny11.TestHelpers.psm1" -Force
Import-Tiny11Module -Name 'Tiny11.WebView2'

BeforeAll {
# The WebView2 version is sourced from the launcher csproj (single source of
# truth); derive the expected value the same way so these tests never hardcode a
# version that drifts when Dependabot bumps the csproj.
$script:ver = Get-Tiny11WebView2Version
}

Describe "Get-Tiny11WebView2Version" {
It "reads the Microsoft.Web.WebView2 version from the launcher csproj" {
$script:ver | Should -Match '^\d+\.\d+\.\d+\.\d+$'
}
It "honors an explicit -CsprojPath override" {
$tmp = New-TempScratchDir
try {
$csproj = Join-Path $tmp 'x.csproj'
Set-Content -Path $csproj -Value '<Project><ItemGroup><PackageReference Include="Microsoft.Web.WebView2" Version="9.9.9.9" /></ItemGroup></Project>'
Get-Tiny11WebView2Version -CsprojPath $csproj | Should -Be '9.9.9.9'
} finally {
Remove-TempScratchDir -Path $tmp
}
}
It "throws when the csproj has no WebView2 PackageReference" {
$tmp = New-TempScratchDir
try {
$csproj = Join-Path $tmp 'x.csproj'
Set-Content -Path $csproj -Value '<Project></Project>'
{ Get-Tiny11WebView2Version -CsprojPath $csproj } | Should -Throw -ExpectedMessage '*no Microsoft.Web.WebView2*'
} finally {
Remove-TempScratchDir -Path $tmp
}
}
}

Describe "Get-Tiny11WebView2SdkPath" {
It "returns paths under the NuGet packages cache for microsoft.web.webview2/<version>" {
$r = Get-Tiny11WebView2SdkPath
$r.CoreDll | Should -Match 'lib[\\/]net462[\\/]Microsoft\.Web\.WebView2\.Core\.dll$'
$r.WpfDll | Should -Match 'lib[\\/]net462[\\/]Microsoft\.Web\.WebView2\.Wpf\.dll$'
$r.NativeDll | Should -Match 'runtimes[\\/]win-x64[\\/]native[\\/]WebView2Loader\.dll$'
$r.VersionDir | Should -Match 'microsoft\.web\.webview2[\\/]1\.0\.2535\.41$'
$r.VersionDir | Should -Match "microsoft\.web\.webview2[\\/]$([regex]::Escape($script:ver))$"
}
It "honors -NugetPackagesRoot override" {
$tmp = New-TempScratchDir
try {
$r = Get-Tiny11WebView2SdkPath -NugetPackagesRoot $tmp
$r.CoreDll | Should -BeLike "$tmp*microsoft.web.webview2*1.0.2535.41*lib*net462*Microsoft.Web.WebView2.Core.dll"
$r.CoreDll | Should -BeLike "$tmp*microsoft.web.webview2*$script:ver*lib*net462*Microsoft.Web.WebView2.Core.dll"
} finally {
Remove-TempScratchDir -Path $tmp
}
Expand All @@ -25,20 +58,24 @@ Describe "Get-Tiny11WebView2SdkPath" {
try {
$env:NUGET_PACKAGES = $tmp
$r = Get-Tiny11WebView2SdkPath
$r.CoreDll | Should -BeLike "$tmp*microsoft.web.webview2*1.0.2535.41*lib*net462*Microsoft.Web.WebView2.Core.dll"
$r.CoreDll | Should -BeLike "$tmp*microsoft.web.webview2*$script:ver*lib*net462*Microsoft.Web.WebView2.Core.dll"
} finally {
$env:NUGET_PACKAGES = $original
Remove-TempScratchDir -Path $tmp
}
}
It "honors an explicit -Version override" {
$r = Get-Tiny11WebView2SdkPath -NugetPackagesRoot 'C:\pkgs' -Version '1.2.3.4'
$r.VersionDir | Should -BeLike '*microsoft.web.webview2*1.2.3.4'
}
}

Describe "Test-Tiny11WebView2SdkPresent" {
It "returns paths object when all 3 DLLs present" {
$tmp = New-TempScratchDir
try {
$libDir = Join-Path $tmp 'microsoft.web.webview2\1.0.2535.41\lib\net462'
$nativeDir = Join-Path $tmp 'microsoft.web.webview2\1.0.2535.41\runtimes\win-x64\native'
$libDir = Join-Path $tmp "microsoft.web.webview2\$script:ver\lib\net462"
$nativeDir = Join-Path $tmp "microsoft.web.webview2\$script:ver\runtimes\win-x64\native"
New-Item -ItemType Directory -Force -Path $libDir | Out-Null
New-Item -ItemType Directory -Force -Path $nativeDir | Out-Null
New-Item -ItemType File -Path (Join-Path $libDir 'Microsoft.Web.WebView2.Core.dll') -Force | Out-Null
Expand Down Expand Up @@ -71,7 +108,7 @@ Describe "Test-Tiny11WebView2SdkPresent" {
It "throws when only some DLLs are present" {
$tmp = New-TempScratchDir
try {
$libDir = Join-Path $tmp 'microsoft.web.webview2\1.0.2535.41\lib\net462'
$libDir = Join-Path $tmp "microsoft.web.webview2\$script:ver\lib\net462"
New-Item -ItemType Directory -Force -Path $libDir | Out-Null
New-Item -ItemType File -Path (Join-Path $libDir 'Microsoft.Web.WebView2.Core.dll') -Force | Out-Null
{ Test-Tiny11WebView2SdkPresent -NugetPackagesRoot $tmp } | Should -Throw -ExpectedMessage '*WebView2 SDK DLL missing*'
Expand Down