In a Debug build, saving a component's .css, .html or .cs file updates the running app: no restart for a stylesheet, one automatic restart for anything that needs new code, and the app keeps its last good UI when the edit does not compile. It works the same under oneapp run, dotnet run and dotnet watch, and in an app started from an IDE: the app watches its own project's sources.
What a save does
| You save | The app |
|---|---|
a component's .html template, and the running build can read the new text | Applied in place, in about 30 ms and with no build. The component's nodes are rebuilt from the new template (OneUI's TemplateReload); its state, the focused element, typed text and scroll positions stay, and child components of a kept tag keep theirs. A save needs no more than expressions, handlers and components the build already has. |
a component's .css (an existing file) | Applied in place. The project is built into a folder of its own; the markup compiler's checked, scoped stylesheet replaces the old one in the page. Every component keeps its state, focus, scroll and typed text. A component that is not on screen yet gets the new stylesheet when it appears. |
a template that needs something new (an expression or handler the build lacks, a component it did not use, a component not on screen), a .cs file, a new or deleted .css, the project file | Restarted. The change needs new code, so the new build starts as a new process and the old one quits once it is gone (a single-instance app hands over cleanly). The values of the components' text, number and boolean state, the text typed into fields and the focused element are put back; lists and other state are rebuilt by the new code. |
| a template with errors the parser finds (an unknown element or attribute, a bad binding syntax) | Failed, at once and with no build: the diagnostic ids, files, lines and columns come back as for a build. The running app is not touched. |
| anything that does not build | Failed. The running app is not touched. The errors (the markup compiler's OUI… diagnostics, the C# compiler's) are printed to the app's stderr as [oneapp reload] path(line,col): error ID: message and returned by the reload verb. Save a fix and the reload continues; an edit that was not applied is not forgotten, so a later stylesheet-only save after a failed template edit restarts. |
A build takes a second or two when little changed. The reload builds the project into <temp>/oneapp-reload-<hash>/ and never writes the folder the app runs from, so it works on Windows, where a running executable is locked. Saves that leave a file's content unchanged do nothing; several saves in a quarter of a second make one build.
Files under bin, obj, .git, node_modules and dot-folders are ignored, and only the project's own folder is watched: components in another project (the kit, a library) are changed by rebuilding.
Telling a tool what happened
The reload harness verb (harness.md):
oneapp call reload # the state now oneapp call reload '{"wait":true,"timeoutMs":60000}' # until the next reload has finished
last.result is applied, restarted, failed or unchanged (the project built but no stylesheet on screen differs from the one the app already shows: not a success, and the summary says so), with files, milliseconds, the replaced sheets and the diagnostics. generation counts reloads and survives a restart, so a client can pass since. After restarted the app is a new process: the discovery file oneapp run uses names it, oneapp apps lists it, and oneapp run keeps relaying the output; a client holding a connection reconnects (the first reload call on the new process shows the restart as last).
Switching it off
- Release builds carry none of it: the
OneAppHotReloadMSBuild property istruefor a Debug build of an executable that is not a test project andfalseotherwise; set it in the project to override. Withfalsethe watcher, the build runner and the restart code are removed by the trimmer and NativeAOT, and nothing at run time can turn them back on. Check a shipped binary withstringsforoneapp reload: no hit. ONEAPP_RELOAD=0turns it off for one run of a Debug build.- The app finds its sources from the project path the build recorded. An app copied away from its sources has nothing to watch and does nothing.
Browser
An app built for browser-wasm is reloaded by dotnet watch. The package's build targets add the markup and style files (**/*.html, **/*.css) to what dotnet watch watches in Debug, and serve oneui-browser.js as a static web asset of their own, so nothing is written into the project. Run it with dotnet watch --non-interactive --no-launch-browser and a Properties/launchSettings.json with launchBrowser: true and a fixed applicationUrl (see samples/Todo.Browser): without a launch profile dotnet watch does not refresh the browser.
- A saved template or stylesheet is compiled into code (the style sheet text is a method's result), so
dotnet watchapplies it as a code change, with no restart. The package's metadata-update handler then mounts each element's component again from the changed code, in place: the page is not loaded again, because a new runtime would start from the assemblies on disk, which do not have the change. State is not kept; a component is rebuilt.
The seam, for contributors
AppHost owns a HotReloader (src/OneApp/HotReload/). A build outcome is a BuildOutcome; IReloadBuild is the seam tests use to fake it. The stylesheet text comes from the generated *.oui.g.cs the compiler is asked to emit beside the build (EmitCompilerGeneratedFiles), so exactly the text the compiler checked is what the page gets. ComponentHost.ReplaceStyleSheet swaps it in on the UI thread.