Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,27 @@ jobs:
- name: Restore
run: dotnet restore "Source/Krypton Components/Krypton Toolkit Suite 2022 - VS2022.sln"

- name: Setup WebView2 SDK
run: |
# Create WebView2SDK directory
mkdir WebView2SDK
# Get latest WebView2 SDK version
$packageId = "Microsoft.Web.WebView2"
$apiUrl = "https://api.nuget.org/v3-flatcontainer/$packageId/index.json"
$response = Invoke-RestMethod -Uri $apiUrl -Method Get
$versions = $response.versions | Sort-Object { [Version]$_ } -Descending
$stableVersions = $versions | Where-Object { $_ -notmatch '[-]' }
$latestVersion = $stableVersions[0]
Write-Host "Using WebView2 SDK version: $latestVersion"
# Download WebView2 SDK assemblies using NuGet
dotnet add "Source/Krypton Components/Krypton.Toolkit/Krypton.Toolkit 2022.csproj" package Microsoft.Web.WebView2 --version $latestVersion --no-restore
# Copy assemblies to WebView2SDK directory
$nugetPath = "$env:USERPROFILE\.nuget\packages\microsoft.web.webview2\$latestVersion\lib\net45"
Copy-Item "$nugetPath\Microsoft.Web.WebView2.Core.dll" "WebView2SDK\"
Copy-Item "$nugetPath\Microsoft.Web.WebView2.WinForms.dll" "WebView2SDK\"
Copy-Item "$nugetPath\WebView2Loader.dll" "WebView2SDK\"
# Remove NuGet package reference
dotnet remove "Source/Krypton Components/Krypton.Toolkit/Krypton.Toolkit 2022.csproj" package Microsoft.Web.WebView2

- name: Build
run: msbuild "Scripts/nightly.proj" /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU"
1 change: 1 addition & 0 deletions Documents/Changelog/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
====

## 2025-11-xx - Build 2511 (V10 - alpha) - November 2025
* Implemented [#1026](https://github.com/Krypton-Suite/Standard-Toolkit/issues/1026), Krypton version of `WebView2`
* Resolved [#2492](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2492), `KryptonForm` does not display '(Administrator)' when elevated
* Resolved [#2502](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2502), **[Breaking Change]** `KryptonCommandLinkButton` updates several properties and their behaviour. See issue for full details.
* Resolved [#2495](https://github.com/Krypton-Suite/Standard-Toolkit/issues/2495), `KryptonProgressBar` private field `_mementoContent` can be null.
Expand Down
182 changes: 182 additions & 0 deletions Documents/WebView2SDK-Setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# WebView2 SDK Setup for KryptonWebView2

## Overview

The KryptonWebView2 control requires the Microsoft WebView2 SDK assemblies to be available for compilation. This document explains how to set up the WebView2 SDK without using NuGet dependencies.

**Quick Start**: Run `run.cmd` and select option 7 "WebView2 SDK Tools" → option 1 "Setup WebView2 SDK" for automated setup.

**Latest Version**: The setup automatically detects and uses the latest stable WebView2 SDK version from NuGet.

## Setup Options

### Option 1: Manual Download (Recommended)

1. **Download WebView2 SDK**
- Visit: https://developer.microsoft.com/en-us/microsoft-edge/webview2/
- Download the latest WebView2 SDK
- Extract the downloaded package

2. **Copy Required Assemblies**
- Create a `WebView2SDK` folder at the repository root (same level as `Source` folder)
- Copy the following files from the extracted SDK to `WebView2SDK`:
```
WebView2SDK/
├── Microsoft.Web.WebView2.Core.dll
├── Microsoft.Web.WebView2.WinForms.dll
└── WebView2Loader.dll
```

3. **Build the Solution**
- Rebuild the entire solution
- The KryptonWebView2 control should now compile successfully

### Option 2: Using NuGet (Temporary)

If you want to quickly get the assemblies without manual download:

1. **Install NuGet Package**
```cmd
dotnet add package Microsoft.Web.WebView2
```

2. **Copy Assemblies**
- Find the NuGet packages folder (usually `%USERPROFILE%\.nuget\packages\`)
- Navigate to the latest version folder (e.g., `microsoft.web.webview2\1.0.3485.44\lib\net45\`)
- Copy the required DLLs to the `WebView2SDK` folder
- Remove the NuGet package reference if desired

3. **Clean Up**
```cmd
dotnet remove package Microsoft.Web.WebView2
```

### Option 3: Using Setup Script (Recommended)

#### Method A: Through Build System Menu
1. **Run the Build System**
```cmd
run.cmd
```
2. **Select Option 7**: "WebView2 SDK Tools"
3. **Select Option 1**: "Setup WebView2 SDK"
4. **Follow the automated process**

#### Method B: Direct Script Execution
Run the provided setup script directly:
```cmd
Setup-WebView2SDK.cmd
```

Both methods will:
- Check if WebView2 SDK is already installed
- Automatically detect the latest stable WebView2 SDK version
- Download and install WebView2 SDK via NuGet (if needed)
- Copy required assemblies to the WebView2SDK directory
- Update project file with the latest version information
- Clean up temporary NuGet references
- Provide clear feedback on the setup status

### Option 4: Update to Latest Version

If you already have WebView2 SDK installed and want to update to the latest version:

#### Method A: Through Build System Menu
1. **Run the Build System**
```cmd
run.cmd
```
2. **Select Option 7**: "WebView2 SDK Tools"
3. **Select Option 2**: "Update WebView2 SDK"
4. **Follow the automated update process**

#### Method B: Direct Script Execution
Run the update script directly:
```cmd
Scripts\Update-WebView2SDK.cmd
```

Both methods will:
- Detect the latest stable WebView2 SDK version
- Download the latest assemblies
- Update the WebView2SDK directory
- Update project file references
- Preserve your existing setup

## File Structure After Setup

Your repository should look like this:
```
Standard-Toolkit/
├── Source/
│ └── Krypton Components/
│ └── Krypton.Toolkit/
│ └── Controls Toolkit/
│ └── KryptonWebView2.cs
├── Scripts/
│ ├── Setup-WebView2SDK.cmd
│ ├── Update-WebView2SDK.cmd
│ ├── Get-LatestWebView2Version.ps1
│ └── Update-WebView2ProjectVersion.ps1
├── WebView2SDK/ ← Created by setup script
│ ├── Microsoft.Web.WebView2.Core.dll
│ ├── Microsoft.Web.WebView2.WinForms.dll
│ └── WebView2Loader.dll
└── run.cmd ← Updated with WebView2 SDK Tools submenu
```

## Verification

After setup, verify that the KryptonWebView2 control compiles:

1. **Build the Solution**
```cmd
dotnet build "Source/Krypton Components/Krypton Toolkit Suite 2022 - VS2022.sln"
```

2. **Check for Errors**
- No compilation errors related to WebView2 types
- KryptonWebView2 appears in the toolbox
- Test form compiles successfully

## Troubleshooting

### "WebView2 types not found" Error
- Ensure the WebView2SDK folder exists at the repository root
- Verify all three DLL files are present in WebView2SDK
- Check that the project file references point to the correct paths
- Rebuild the solution completely

### Assembly Loading Errors
- Ensure the DLLs are the correct architecture (AnyCPU or x64)
- Check that the DLLs are not corrupted
- Verify the file permissions allow reading

### Designer Issues
- Reset the Visual Studio toolbox
- Close and reopen Visual Studio
- Ensure the control compiles without errors first

## Runtime Requirements

Remember that end users need the WebView2 Runtime installed:

- **Evergreen Distribution**: Users install from Microsoft's website
- **Fixed Version**: Bundle with your application
- **Download**: https://developer.microsoft.com/en-us/microsoft-edge/webview2/

## Support

If you encounter issues:

1. Check the WebView2 documentation: https://docs.microsoft.com/en-us/microsoft-edge/webview2/
2. Verify your setup matches the requirements
3. Test with the provided KryptonWebView2Test form
4. Report issues to the Krypton Toolkit repository

## Notes

- The WebView2SDK folder should be added to `.gitignore` if you don't want to commit the assemblies
- The assemblies are referenced with `Private=False` so they won't be copied to output
- This setup allows the control to compile without NuGet dependencies
- Runtime WebView2 functionality requires the WebView2 Runtime to be installed on target systems
19 changes: 19 additions & 0 deletions Scripts/Check-WebView2Version.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off
echo Checking WebView2 SDK version...
echo.

if exist "WebView2SDK\Microsoft.Web.WebView2.Core.dll" (
echo Current installed version:
powershell -Command "Get-ItemProperty 'WebView2SDK\Microsoft.Web.WebView2.Core.dll' | Select-Object -ExpandProperty VersionInfo | Select-Object -ExpandProperty FileVersion"
echo.
echo Latest available version:
powershell -ExecutionPolicy Bypass -File "%~dp0Get-LatestWebView2Version.ps1"
) else (
echo WebView2 SDK is not installed.
echo.
echo Latest available version:
powershell -ExecutionPolicy Bypass -File "%~dp0Get-LatestWebView2Version.ps1"
)

echo.
pause
41 changes: 41 additions & 0 deletions Scripts/Get-LatestWebView2Version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Get-LatestWebView2Version.ps1
# Script to get the latest stable version of Microsoft.Web.WebView2 from NuGet

param(
[switch]$Prerelease = $false
)

try {
# Use NuGet API to get package information
$packageId = "Microsoft.Web.WebView2"
$apiUrl = "https://api.nuget.org/v3-flatcontainer/$packageId/index.json"

Write-Host "Fetching latest version information for $packageId..." -ForegroundColor Green

# Get package versions
$response = Invoke-RestMethod -Uri $apiUrl -Method Get

if ($Prerelease) {
# Include prerelease versions - sort by version number only
$versions = $response.versions | Where-Object { $_ -match '^\d+\.\d+\.\d+' } |
Sort-Object { [Version]($_ -replace '-.*$', '') } -Descending
$latestVersion = $versions[0]
} else {
# Only stable versions (no prerelease identifiers)
$stableVersions = $response.versions | Where-Object { $_ -notmatch '[-]' } |
Sort-Object { [Version]$_ } -Descending
$latestVersion = $stableVersions[0]
}

if ($latestVersion) {
Write-Host "Latest version: $latestVersion" -ForegroundColor Yellow
return $latestVersion
} else {
Write-Error "No suitable version found"
return $null
}
}
catch {
Write-Error "Failed to fetch version information: $($_.Exception.Message)"
return $null
}
90 changes: 90 additions & 0 deletions Scripts/Setup-WebView2SDK.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@echo off
echo Setting up WebView2 SDK for KryptonWebView2 control...
echo.

REM Check if WebView2SDK directory exists and has the required files
if exist "WebView2SDK\Microsoft.Web.WebView2.Core.dll" (
if exist "WebView2SDK\Microsoft.Web.WebView2.WinForms.dll" (
if exist "WebView2SDK\WebView2Loader.dll" (
echo WebView2 SDK assemblies are already present!
echo.
echo Files found:
dir WebView2SDK\*.dll
echo.
echo The KryptonWebView2 control should compile successfully.
echo You can now build the solution and use the control.
echo.
pause
exit /b 0
)
)
)

REM Create WebView2SDK directory if it doesn't exist
if not exist "WebView2SDK" (
echo Creating WebView2SDK directory...
mkdir WebView2SDK
)

echo.
echo WebView2 SDK assemblies are missing. Setting up automatically...
echo.

REM Get the latest WebView2 SDK version
echo Detecting latest WebView2 SDK version...
powershell -ExecutionPolicy Bypass -File "%~dp0Get-LatestWebView2Version.ps1" > temp_version.txt 2>&1
set /p WEBVIEW2_VERSION=<temp_version.txt
del temp_version.txt

if "%WEBVIEW2_VERSION%"=="" (
echo Failed to detect latest version, using fallback version 1.0.2478.35
set WEBVIEW2_VERSION=1.0.2478.35
) else (
echo Using WebView2 SDK version: %WEBVIEW2_VERSION%
)

REM Try to download and setup WebView2 SDK automatically
echo Attempting to install WebView2 SDK via NuGet...
dotnet add "Source/Krypton Components/Krypton.Toolkit/Krypton.Toolkit 2022.csproj" package Microsoft.Web.WebView2 --version %WEBVIEW2_VERSION%

if %ERRORLEVEL% EQU 0 (
echo.
echo Copying WebView2 assemblies to WebView2SDK folder...

REM Copy the assemblies from NuGet cache
copy "%USERPROFILE%\.nuget\packages\microsoft.web.webview2\%WEBVIEW2_VERSION%\lib\net45\Microsoft.Web.WebView2.Core.dll" "WebView2SDK\" >nul 2>&1
copy "%USERPROFILE%\.nuget\packages\microsoft.web.webview2\%WEBVIEW2_VERSION%\lib\net45\Microsoft.Web.WebView2.WinForms.dll" "WebView2SDK\" >nul 2>&1
copy "%USERPROFILE%\.nuget\packages\microsoft.web.webview2\%WEBVIEW2_VERSION%\runtimes\win-x64\native\WebView2Loader.dll" "WebView2SDK\" >nul 2>&1

REM Remove the NuGet package reference since we're using local assemblies
dotnet remove "Source/Krypton Components/Krypton.Toolkit/Krypton.Toolkit 2022.csproj" package Microsoft.Web.WebView2

REM Update project file with the latest version
echo Updating project file with latest version...
powershell -ExecutionPolicy Bypass -File "%~dp0Update-WebView2ProjectVersion.ps1"

echo.
echo WebView2 SDK setup completed successfully!
echo.
echo Installed version: %WEBVIEW2_VERSION%
echo Files copied:
dir WebView2SDK\*.dll
echo.
echo You can now build the solution and use the KryptonWebView2 control.
) else (
echo.
echo Automatic setup failed. Please follow manual setup instructions:
echo.
echo MANUAL SETUP INSTRUCTIONS:
echo 1. Download the WebView2 SDK from: https://developer.microsoft.com/en-us/microsoft-edge/webview2/
echo 2. Extract the following files to the WebView2SDK folder:
echo - Microsoft.Web.WebView2.Core.dll
echo - Microsoft.Web.WebView2.WinForms.dll
echo - WebView2Loader.dll
echo.
echo Alternative: Use NuGet Package Manager to install Microsoft.Web.WebView2
echo and copy the assemblies from the packages folder to WebView2SDK.
)

echo.
pause
Loading
Loading