How kopecp/web-view2-demo_multiwersion works
1. Overall shape
This repo is a two-process demo architecture: a Revit add-in written in .NET and a separate web application in Vue 2. The add-in hosts the Revit-side runtime; the web app is the UI surface. They communicate through a local bridge, and the actual Revit actions are pushed into versioned, load-on-demand DLL packages.
2. Revit add-in boundary
RevitWebView2Demo is the main executable add-in. It contains the Revit entry points, dockable window/WebView hosting, event handlers, and the runtime that loads and executes packages. This is the boundary that talks directly to Revit API and must respect Revit’s external event model.
3. Shared contracts
RevitWebView2Demo.Abstractions defines the contract layer between the host and the packages. IRevitPackageCommand and RevitPackageContext establish the minimum interface and execution context needed so that package DLLs can be loaded independently without tight coupling to the host implementation.
4. Versioned package subsystem
RevitWebView2Demo.Packages.CreateSheet and RevitWebView2Demo.Packages.SelectElements are sample Revit API packages. Each package has its own project and manifest, and is meant to be deployed as a separately versioned artifact rather than compiled into the host add-in. This is the key “plugin-of-plugins” boundary in the architecture.
5. Package runtime inside the add-in
The PackageRuntime folder implements the dynamic loading pipeline:
- manifest parsing and package metadata,
- path validation,
- assembly resolution,
- loading package assemblies,
- queueing/executing package requests,
- returning execution results.
This runtime is the mechanism that turns a web request into a live Revit API operation.
6. Safety and isolation around package loading
PackagePathGuard, PackageAssemblyResolver, PackageSourceMarker, and related types show that package loading is intentionally constrained. The host validates where packages come from and controls resolution so the add-in does not blindly load arbitrary DLLs. This is an important architectural boundary because packages are externalized and versioned.
7. Revit UI interaction model
Revit actions are mediated by event handlers such as RevitWv2EventHandler, SelectExternalEventHandler, and UI commands like ShowWebViewDockCommand / ShowWebView2Window. This reflects the Revit pattern where external events are used to marshal work back onto the Revit UI thread rather than calling API operations directly from the web bridge.
8. Web-to-Revit communication layer
BrowserBridge contains the local messaging infrastructure: a server, message envelopes, and outbound message types. Its role is to carry commands and responses between the browser UI and the add-in. The README indicates a local WebSocket bridge is used, with a fallback path through registry relay.
9. Registry relay as an alternate connection path
RegistryRelay is a secondary communication subsystem consisting of client, web connection, message types, and a command to inspect active connections. Architecturally, this is a discovery/relay mechanism that helps the browser and the add-in find each other locally without hard-wiring a single communication path.
10. Web application
The web folder is a standalone Vue 2 application with routing, a Revit demo component, and a small utility layer for webview/connection integration. It is the user-facing control plane for triggering Revit operations, not the place where Revit API logic lives.
11. Web server and published package registry
web/server.js and web/revit-registry.js provide the local HTTP/WebSocket-serving side for development and connection coordination. The public/revit-packages/... tree acts as a package registry: the packaged DLLs and their package.json manifests are published here so the add-in can fetch them at runtime.
12. Build and packaging pipeline
tools/PackRevitPackage.ps1 is the packaging step that turns a package DLL into the web-published artifact format. The repo’s architecture depends on this split: packages are built from the Revit-package projects, packed, then served from the web app’s public directory for runtime download.
13. Deployment assumptions
The solution is explicitly tied to Windows, Autodesk Revit versions 2022/2024/2025, and local install paths for RevitAPI.dll/RevitAPIUI.dll. The add-in build copies artifacts into the user’s Revit add-ins folder, while the web app assumes a local dev server at http://localhost:8080/ during development.
14. End-to-end data flow
A typical request path is:
web UI action → browser bridge / relay message → add-in receives request → package runtime resolves and loads the target versioned DLL → external event executes Revit API work → result returns back through the bridge to the web UI.
This is the central architecture diagram to capture: UI, bridge, host runtime, and package execution are separate layers with explicit message passing between them.
Main entry points: RevitPackageLoader.cs Package runtime · App.vue Vue app · BrowserBridgeServer.cs Browser bridge · App.cs Add-in host
Components 21
Revit add-in
Revit-hosted .NET boundary, UI, bridge, and package runtime.
- Add-in host · Main executable add-in entry point and Revit integration boundary.
RevitWebView2Demo/App.cs - WebView UI · Dockable window and WebView2 window hosting for the browser surface.
RevitWebView2Demo/WebView2Window.xaml.cs - UI commands · Commands that open the WebView window and docked panel.
RevitWebView2Demo/ShowWebViewDockCommand.cs - External events · External-event handlers that marshal work back onto the Revit UI thread.
RevitWebView2Demo/RevitWv2EventHandler.cs - Browser bridge · Local messaging layer between browser UI and the add-in.
RevitWebView2Demo/BrowserBridge/BrowserBridgeServer.cs - Registry relay · Alternate local discovery and connection path for the browser and add-in.
RevitWebView2Demo/RegistryRelay/RegistryClient.cs - Package runtime · Dynamic loading and execution pipeline for externalized Revit packages.
RevitWebView2Demo/PackageRuntime/RevitPackageLoader.cs - Path guard · Constrains package origins and validates load paths before execution.
RevitWebView2Demo/PackageRuntime/PackagePathGuard.cs - Assembly resolver · Resolves package assemblies during load and execution.
RevitWebView2Demo/PackageRuntime/PackageAssemblyResolver.cs - Exec queue · Queues package execution requests and returns results.
RevitWebView2Demo/PackageRuntime/PackageExecutionQueueItem.cs
Contracts
Shared abstractions used by host and versioned packages.
- Package API · Shared package contract interface for independently loaded commands.
RevitWebView2Demo.Abstractions/IRevitPackageCommand.cs - Package context · Minimum execution context passed from host into packages.
RevitWebView2Demo.Abstractions/RevitPackageContext.cs
Versioned packages
Load-on-demand Revit API package projects and their manifests.
- Create Sheet · Sample package that performs sheet creation via the Revit API.
RevitWebView2Demo.Packages.CreateSheet/CreateSheetCommand.cs - Select Elements · Sample package that drives element selection via the Revit API.
RevitWebView2Demo.Packages.SelectElements/SelectElementsCommand.cs
Web app
Standalone Vue 2 control plane and local connection server.
- Vue app · Standalone Vue 2 application used as the user-facing control plane.
web/src/App.vue - Demo view · Primary Revit demo view exposed by the web UI.
web/src/views/Home.vue - Webview utils · Client-side webview integration helpers for browser-to-host communication.
web/src/utils/webview2.js - Local server · Local HTTP/WebSocket serving and coordination for development.
web/server.js - Registry service · Web-side registry coordination for locating the host connection.
web/revit-registry.js - Package registry · Published package manifests and archives served to the host at runtime.
web/public/revit-packages/create-sheet/1.0.0/package.json
Packaging
Build-time packaging step for publishing package artifacts.
- Pack script · Build-time script that turns a package DLL into a web-published artifact.
tools/PackRevitPackage.ps1
Connections 27
- Add-in host → WebView UI: hosts · The add-in creates and hosts the WebView2 UI surface.
- Add-in host → UI commands: exposes · Revit commands open the window or dockable panel.
- UI commands → WebView UI: opens · Commands launch the browser UI container.
- WebView UI → Browser bridge: connects · The webview UI attaches to the local browser bridge.
- Browser bridge → Vue app: messages · Browser messages carry commands and responses to the Vue app.
- Vue app → Demo view: renders · The main app routes to the demo view.
- Vue app → Webview utils: uses · Client helpers mediate webview communication.
- Vue app → Local server: served by · The app is hosted by the local dev server.
- Local server → Registry service: coordinates · Server-side coordination supports discovery and relay.
- Registry service → Registry relay: relays · Registry coordination helps the browser and add-in find each other.
- Browser bridge → Package runtime: dispatches · Incoming browser requests are routed into package execution.
- Package runtime → Path guard: validates · Package origins and paths are checked before load.
- Package runtime → Assembly resolver: loads · Assembly resolution is delegated during package loading.
- Package runtime → Exec queue: queues · Execution requests are queued and processed through the runtime.
- Package runtime → Package API: depends on · Loaded packages implement the shared command contract.
- Package runtime → Package context: provides · The host passes execution context into package commands.
- Package runtime → Create Sheet: executes · The runtime can load and run the Create Sheet package.
- Package runtime → Select Elements: executes · The runtime can load and run the Select Elements package.
- Create Sheet → Package API: implements · Package command follows the shared contract.
- Select Elements → Package API: implements · Package command follows the shared contract.
- Create Sheet → Package context: uses · Package work is driven by the host-provided context.
- Select Elements → Package context: uses · Package work is driven by the host-provided context.
- Add-in host → External events: marshals · Revit work is executed through external events.
- External events → Package runtime: triggers · External events trigger package execution on the Revit thread.
- Registry relay → Browser bridge: fallback · Registry relay acts as an alternate connection path.
- Package registry → Package runtime: published for · Published package artifacts are fetched by the host runtime.
- Pack script → Package registry: builds · The packaging script produces the published artifact format.