/dotnet-remote-watch

Turns dotnet-watch into a client-server model.

Primary LanguageC#MIT LicenseMIT

dotnet-remote-watch

NuGet Badge AppVeyor Badge DotNet Badge License Badge

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.

Installation

dotnet tool install --global drw

Usage

  1. Add the following section to project file:

    <Import Project="$(RemoteWatchTargets)" Condition="'$(RemoteWatchTargets)' != ''" />
  2. Launch server:

    dotnet remote-watch

    remote-watch is supposed to be used in the same way as dotnet watch and it will launch and forward all arguments to dotnet watch after initialization.

  3. Launch HotReload.Client generated in the output directory. It will launch the target App after connecting to remote-watch.

  4. Update source code and observe the changes.

Environment variables

  • DOTNET_HOTRELOAD_PORT: The port to use for the client-server communication, default is 3000.

MSBuild

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.

How it works

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.

dotnet watch

dotnet-watch

dotnet remote-watch

dotnet-remote-watch