Turns dotnet watch into a client-server model, so that the server (watcher) and the client (App) do not have to be run in the same host.
The primary intended use case is to run dotnet watch inside a dev container, and have the client run on the host, which does not necessarily have the .NET SDK/runtime installed. Hot-reloading Windows desktop apps (e.g., WPF, WinUI) with dev containers is now possible.
With some custom port forwarding, it should be possible to hot-reload an application on a remote machine or container.
dotnet tool install --global drw-
Add the following section to project file:
<Import Project="$(RemoteWatchTargets)" Condition="'$(RemoteWatchTargets)' != ''" />
-
Launch server:
dotnet remote-watch
remote-watchis supposed to be used in the same way asdotnet watchand it will launch and forward all arguments todotnet watchafter initialization. -
Launch
HotReload.Clientgenerated in the output directory. It will launch the target App after connecting toremote-watch. -
Update source code and observe the changes.
DOTNET_HOTRELOAD_HOST: The hostname/IP address of the server, defaults tolocalhost.DOTNET_HOTRELOAD_PORT: The port to use for the client-server communication, default is 3000.
Consider setting the following MSBuild properties in the project file or environment variables:
SelfContained: Set to true so that the client can run on an environment without the .NET SDK/runtime installed.RuntimeIdentifier: Set the target runtime identifier if it's different from where the watcher runs.
remote-watch intercepts the named pipe connection between dotnet-watch and Microsoft.Extensions.DotNetDeltaApplier.dll (injected into the target application via StartupHooks). The server forwards the intercepted data to HotReload.Client through a TCP connection (tcp://localhost:$DOTNET_HOTRELOAD_PORT), and HotReload.Client forwards the data to the target application through another named pipe.
Note that the internal implementation of dotnet-watch may change in the future.