Hot reload
dotnet watch reloads the browser when a file changes. For C# that works out of the box. For
.ts it needs one line, because in its default hot reload mode dotnet watch runs no build when
a .ts file is saved, so the .js would go stale.
Turn it on
XML
<PackageReference Include="Extrode.Pare.AspNetCore" Version="0.6.2" />
C#
using Extrode.Pare.AspNetCore;
builder.AddPareDevelopment(); // before builder.Build(); does nothing outside Development
Now this happens on every save:
- At start-up the app strips every source that is out of date.
- It reads
Extrode.Pare.development.json, which the build puts next to the app and never publishes, to know where each source's output goes. - A rejected file is logged as
file:line:col: error PARE...and the old.jsstays. - Deleting a source deletes its output under
obj/. - It covers sources served with
PareServeAtand sources of a Razor class library that the app references as a project.
If you set PareOutDir, pass the same folder: builder.AddPareDevelopment(o => o.OutDir = "...").
AddPareDevelopment also adds dotnet watch's browser refresh to WebApplication.CreateSlimBuilder
apps, which never run the hosting startup that adds it.
Limits
- A
.tsfile added whiledotnet watchruns is stripped, but the page gets 404 for it until the next build. Press Ctrl+R indotnet watchto rebuild. The log says so. - A request for a deleted source's output answers 500 in Development until the next build.
- In Development the server still serves
.tssource files on disk with a warning.MapStaticAssetsserves any file on disk in Development, andUseStaticFilesserves everything underwwwroot. Published output never contains them.
If it does not reload
PublishAotproject: add<StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>. Without itdotnet watchsays "Project does not support Hot Reload".- Run
dotnet watchfrom the project directory. With--projectfrom another folder, .NET SDK 10.0.401 on macOS fails to readobj\Debug/.../staticwebassets.development.jsonand never refreshes the page. - No package?
dotnet watch --no-hot-reloadrebuilds and restarts on every save (about 3 seconds on the sample) and you reload the page yourself.