Add Runic to an existing app

On this page

Use this path when you already have a .NET console or desktop project and a frontend, and want them to talk through typed Windows and Views. To start from nothing, create a project instead; the steps below reproduce what the template sets up. Replace <VERSION> with the current release from the package catalog and keep Application SDK packages on that version; Runic.Application.Views.CsWebUi is still a prerelease, 0.17.0-preview.1, and needs CsWebUi 2.5.0-beta.4.9 or later. Runic Translations and Runic Command Line have independent release versions.

For a package-only GTK 4 consumer and its scoped/native shutdown ownership, see Build a desktop app from published packages.

For an existing WPF shell, follow incremental WPF migration to add native navigation or embed an individual web View.

1. Add the packages #

Choose one host adapter. Runic Desktop, the default, opens native windows with the embedded WebView and adds platform services. CS-WebUI opens a browser window and is supported on a best-effort basis (see choosing a host and MVVM library):

dotnet add package Runic.Application.Views.Desktop --version <VERSION>
dotnet add package Runic.Desktop.NativeServer --version <VERSION>
# or, for a browser window:
dotnet add package Runic.Application.Views.CsWebUi --version <VERSION>

Since SDK 0.15.0, a Runic Desktop application also references the server that serves its pages: Runic.Desktop.NativeServer, which needs no ASP.NET Core and which the template uses, or Runic.Desktop.Kestrel for an application that uses ASP.NET Core itself. Without either the build fails with RUNICDESK004; see the presentation server.

Add the ReactiveUI adapter, which brings ReactiveUI 26, and the dependency injection container at the version the template uses:

dotnet add package Runic.Application.Views.ReactiveUI --version <VERSION>
dotnet add package Microsoft.Extensions.DependencyInjection --version 10.0.14

For CommunityToolkit.Mvvm ViewModels, add CommunityToolkit.Mvvm instead of Runic.Application.Views.ReactiveUI:

dotnet add package CommunityToolkit.Mvvm --version 8.4.2

2. Opt the project in #

The host adapter brings the build targets. They expect the frontend in a Frontend folder next to the project file; set RunicApplicationFrontendDirectory if yours lives elsewhere. Opt in to dotnet runic dev and dotnet runic doctor in the project file:

<RunicApplicationFrontendWindowProject>true</RunicApplicationFrontendWindowProject>

Install the project-local dotnet runic tool:

dotnet new tool-manifest
dotnet tool install --local dotnet-runic --version <VERSION>

3. Declare a Window and its Views #

Keep your ViewModels as they are; they need INotifyPropertyChanged and at least one property or command. Declare the Window over the root ViewModel and a View for each ViewModel the Window presents:

public sealed partial class WorkspaceWindow : RunicWindow<WorkspaceViewModel>;

public sealed partial class WelcomeView : ReactiveRunicView<WelcomeViewModel>;
public sealed partial class CounterView : ReactiveRunicView<CounterViewModel>;

With CommunityToolkit.Mvvm, the Views are RunicView<TViewModel>. A Window with a single ViewModel needs no Views.

Since SDK 0.11.0, the runic-view item template from Runic.Application.Templates writes a View and its ViewModel into a project that references a Runic host or Runic.Application.Views: dotnet new runic-view --name Settings adds SettingsView.cs and SettingsViewModel.cs. --window declares a Window instead, --view-models toolkit uses CommunityToolkit.Mvvm, and --namespace sets the namespace (by default the project's RootNamespace once it has been restored). Register the new ViewModel yourself.

4. Register and open the Window #

Register each ViewModel with the lifetime your application needs; the Window's root ViewModel must be scoped. AddRunicViews() is generated for your project, and AddRunicPlatformServices() gives ViewModels the Window's file dialogs and clipboard:

public static IServiceCollection AddWorkspace(this IServiceCollection services)
{
    services.AddRunicReactiveModelContext();
    services.AddScoped<WorkspaceViewModel>();
    services.AddScoped<WelcomeViewModel>();
    services.AddScoped<CounterViewModel>();
    // Generated by the build: the Window and View Bridges and the View locator.
    services.AddRunicViews();
    // ...
    services.AddRunicPlatformServices();
    return services;
}

With ReactiveUI, AddRunicReactiveModelContext() runs the commands' notifications on the Window's model context; leave it out with CommunityToolkit.Mvvm. Then run the application on the host, and open the Window in its body. RunicDesktopHost.Run starts the event loop the platform needs, so call it before any await:

await using var provider = new ServiceCollection().AddWorkspace().BuildServiceProvider(new ServiceProviderOptions
{
    ValidateScopes = true,
    ValidateOnBuild = true
});
...
return RunicDesktopHost.Run(provider, options, hostOptions, RunAsync);
...
static async Task<int> RunAsync(IRunicWindowHost host)
{
    await using var window = await host.OpenWindowAsync<WorkspaceWindow>(new RunicWindowOptions { Width = 1000, Height = 700 });
    await window.WaitForCloseAsync();
    return 0;
}

The Window serves the built frontend from the www folder next to the executable. With CS-WebUI, call RunicCsWebUiHost.Run(provider, RunAsync) instead; the body is the same. The template's hostOptions set RunicDesktopHostOptions.ContentSecurityPolicy outside Development; pass RunicDesktopHost.Run(provider, options, RunAsync) to send no policy. Since SDK 0.11.0 the Views Bridge works without 'unsafe-eval', so remove it from your pages' policy unless another dependency evaluates strings. The tutorial walks through the generated Program.cs.

5. Connect the frontend #

From the frontend folder, install the shared runtime and the binding for your framework:

npm install --save-exact @runic-artifex/views@<VERSION>
npm install --save-exact @runic-artifex/react@<VERSION>

Use @runic-artifex/vue, @runic-artifex/svelte or @runic-artifex/angular for those frameworks, or only @runic-artifex/views for plain TypeScript. A SvelteKit app adds @runic-artifex/sveltekit, whose runicAdapter() prerenders the pages, next to @runic-artifex/svelte. Add @runic-artifex/vite-plugin-runic as a development dependency for Runic diagnostics and for dotnet runic dev's session check, which confirms that the development server on its port is the one it started. Since SDK 0.11.0, runic() in a Vite configuration needs the plugin from the same release, and an Angular project puts runicDevSessionProxy() in the serve target's proxyConfig. Without them, an older project is not checked. Since SDK 0.14.0, a SvelteKit configuration adds runic({ html: false }) next to sveltekit() and imports @runic-artifex/vite-plugin-runic/client from src/hooks.client.ts, which also brings the development timeline and the stale-input warning; runicDevSession(), which SDK 0.11.0 used there, is removed in SDK 0.15.0, and a configuration that still imports it fails to load. An Angular project loads the same client from main.ts behind ngDevMode. Since SDK 0.15.0, the client also reports each open View's state, which the dock (the Vite DevTools dock) shows on a Views card with the route, revision and presentation epoch, and lists commands that .NET answered superseded on a Superseded commands card. Both are in /__runic/state too (views and the timeline), for the Angular CLI. The production build replaces the client with an empty module.

The page loads the host's scripts before your module. The template loads a host-neutral Views client:

<script src="webui.js"></script>
<!-- The host copies its Views client to runic-views.js, so one build runs on every host. -->
<script src="runic-views.js"></script>

Since SDK 0.7.0-preview.9, both host packages copy their Views client to runic-views.js, so one frontend build runs on Runic Desktop and CS-WebUI, and the Vite configuration is runic() with base: "./" on every host. A project that references both host packages sets RunicApplicationHost to desktop or cswebui. Before 0.7.0-preview.9, pages loaded runic-desktop-views.js with Runic Desktop and used runic({ desktop: true }), which also loads the Desktop bootstrap, or loaded runic-cswebui.js with CS-WebUI. SDK 0.22.0 deprecated those host-named copies, and 0.23.0 removed them: a page that still loads one gets a 404 for it and no Bridge, so its Views never connect, and the build reports warning RUNICBRIDGE019 naming the page. Load runic-views.js instead. A copy of your own under the old name is served as before but not updated by the build; rename it to runic-views.js. Since SDK 0.11.0, update a copy of the script that you keep outside www/, because an older script receives no state.

dotnet build now writes the typed clients to Frontend/src/generated, builds the frontend with its build script and copies Frontend/dist to www next to the executable. Add Frontend/src/generated to .gitignore. Build the frontend with relative asset URLs (Vite's base: "./") so the www folder can move. The tutorial shows how the generated clients are used from components. Since SDK 0.11.0, <RunicApplicationFrontendDelivery>Embedded</RunicApplicationFrontendDelivery> packs the frontend into the application assembly instead of www, for Runic Desktop and WPF hosts, and since SDK 0.15.0 for CS-WebUI, which serves it from the assembly without extracting it; before, CS-WebUI kept www and warned with RUNICBRIDGE030. RunicApplicationFrontendPackageManager takes npm, pnpm or bun; another value warns with RUNICBRIDGE029.

To add a Window to an existing web app, for example a frontend in a monorepo that reuses the app's components, styles and translations, see Adding a Window to an existing web app in the Views README. It covers Vite resolve.alias and resolve.dedupe, matching TypeScript paths, Tailwind @source, and the RunicApplicationFrontendInput items that make dotnet build rebuild the frontend when shared sources outside its folder change.

6. Run it #

dotnet tool restore
dotnet runic dev

dotnet runic doctor reports a missing opt-in, package or frontend lock file. Since SDK 0.11.0 it also warns when the installed @runic-artifex/views does not match the restored Runic.Application.Views (views-package-versions) and when the project's ApplicationId is not a valid reverse-DNS name (application-id). Node.js 24 is the certified version; Node.js 26 passes with a warning. dotnet runic dev takes --launch-profile, --no-build, -e/--environment NAME=VALUE and -v/--verbosity.