dotnet-watch(1)
dotnet-watch(1) Β· .NET Documentation Β· bestie edition π
This article applies to: βοΈ .NET 6 SDK and later versions
β¨ NAME β¨
dotnet-watch β okay so this is the tool that restarts or hot reloads the app you point it at, or runs a dotnet command you name, the literal second it notices your source code changed. no cap. π¦
πΈ SYNOPSIS πΈ
dotnet watch [<command>]
[--artifacts-path <ARTIFACTS_DIR>] [--disable-build-servers]
[--list] [--no-hot-reload] [--no-self-contained]
[--non-interactive] [--project <PROJECT>] [--sc|--self-contained]
[-q|--quiet] [-v|--verbose] [--version]
[--] <forwarded arguments>
dotnet watch -?|-h|--help
π DESCRIPTION π
dotnet watch is a file watcher. the moment it clocks a change, it runs dotnet run or whatever dotnet command you told it to run. and if it's running dotnet run and your change is one that hot reload supports? it hot reloads your app. if the change isn't supported, it just restarts the whole app instead. either way, the vibe is fast iterative development straight from the command line and it is genuinely so good. π₯
while dotnet watch is doing its thing, you can force the app to rebuild and restart by smashing Ctrl+R in the command shell. but heads up, bestie β that only works while the app is running. like, if you run dotnet watch on a console app that finishes before you get to press Ctrl+R, pressing Ctrl+R does absolutely nothing π. the good news though? dotnet watch is still watching your files in that case, and it'll restart the app the moment a file gets updated. main character behavior honestly.
π Response compression π
if dotnet watch runs an app that uses response compression, the tool can't inject the browser refresh script. on .NET 7 and later, the tool throws a warning at you that looks like this:
warn: Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware[4]
Unable to configure browser refresh script injection on the response. This may have been caused by the response's Content-Encoding: `br'. Consider disabling response compression.
so if you don't wanna disable response compression, you can just manually add the browser refresh JavaScript reference to your app's pages instead:
@if (Environment.GetEnvironmentVariable("__ASPNETCORE_BROWSER_TOOLS") is not null)
{
<script src="/_framework/aspnetcore-browser-refresh.js"></script>
}
π¦ ARGUMENTS π¦
<command>
on .NET 7 SDK and earlier, dotnet watch can run any command that gets dispatched through the dotnet executable β built-in CLI commands, global tools, all of it. if you can run dotnet <command>, you can run dotnet watch <command>. periodt.
on .NET 8 SDK and later, it's a tighter lineup: dotnet watch can run dotnet run, dotnet build, or dotnet test. so you specify run, build, or test for <command>.
if you don't specify the child command at all, it defaults to run for dotnet run. π
<forwarded arguments>
anything you drop after a double dash (--) gets passed along to the child dotnet process. running dotnet watch run? then those arguments are options for dotnet run. running dotnet watch test? then they're options for dotnet test. simple as that, iykyk β¨
π OPTIONS π
--artifacts-path <ARTIFACTS_DIR>β all the build output files from the executed command go into subfolders under the path you specify, split up by project. for more info, see Artifacts Output Layout. available since .NET 8 SDK. π--disable-build-serversβ forces the command to ignore any persistent build servers. it's the consistent way to kill all use of build caching and force a build from scratch. why would you want that? because a build that doesn't lean on caches is chef's kiss when the caches might be corrupted or just plain wrong for some reason. available since .NET 7 SDK. π§--listβ lists every discovered file without starting the watcher. like window shopping but for files π--no-self-containedβ equivalent to--self-contained false. that's it, that's the whole thing.--no-hot-reloadβ suppress hot reload for supported apps. sometimes you just want the restart, you know?--non-interactiveβ runsdotnet watchin non-interactive mode. use this when you want to prevent console input from ever being requested. and btw, when hot reload is enabled and a rude edit gets detected,dotnet watchrestarts the app. available since .NET 7 SDK. π--project <PATH>β specifies the path of the project file to run. you can give it just the folder, or the folder plus the project file name. if you don't say anything, it defaults to the current directory. π--sc|--self-containedβ publishes the .NET runtime right along with your application, so the runtime does not need to be installed on the target machine. the default istrue. β¨-q|--quietβ suppresses all output generated by thedotnet watchcommand, except warnings and errors. important: this option is not passed on to child commands. so for example, output fromdotnet restoreanddotnet runstill comes through. π-v|--verboseβ shows verbose output for debugging. when you need to see everything.--versionβ shows the version ofdotnet watch. π--β the double-dash option (β) can be used to delimitdotnet watchoptions from arguments that get passed to the child process. using it is optional. when you don't use it,dotnet watchtreats the first unrecognized argument as the beginning of the arguments it should pass into the childdotnetprocess. π¦-?|-h|--helpβ prints out a description of how to use the command. the classic. the icon. πΈDOTNET_HOTRELOAD_NAMEDPIPE_NAMEβ dotnet watch sets this one itself when it's about to launch your app, and it says which named pipe to use.DOTNET_USE_POLLING_FILE_WATCHERβ set it to1ortrueand dotnet watch swaps to a polling file watcher instead of<xref:System.IO.FileSystemWatcher?displayProperty=nameWithType>. Polling is literally required on some file systems β network shares, Docker mounted volumes, and other virtual file systems, iykyk. The<xref:Microsoft.Extensions.FileProviders.PhysicalFileProvider>class readsDOTNET_USE_POLLING_FILE_WATCHERto decide whether the<xref:Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch%2A?displayProperty=nameWithType>method will lean on the<xref:Microsoft.Extensions.FileProviders.Physical.PollingFileChangeToken>.DOTNET_WATCHβ dotnet watch sets this to1on every single child process it launches. no cap.DOTNET_WATCH_AUTO_RELOAD_WS_HOSTNAMEβ the browser refresh server mechanism inside dotnet watch reads this to figure out the WebSocket host environment. Fun part: the value127.0.0.1gets replaced withlocalhost, and thehttp://andhttps://schemes get swapped forws://andwss://respectively.DOTNET_WATCH_ITERATIONβ dotnet watch sets this to1, and then bumps it by one every time a file changes and the command restarts or hot reloads your app. it's the lil counter of character development β¨DOTNET_WATCH_SUPPRESS_BROWSER_REFRESHβ set to1ortrueand dotnet watch will not refresh browsers when it detects file changes.DOTNET_WATCH_SUPPRESS_EMOJISβ starting with the .NET SDK 6.0.300, dotnet watch emits non-ASCII characters to the console, like this:
dotnet watch π₯ Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
π‘ Press "Ctrl + R" to restart.
dotnet watch π§ Building...
dotnet watch π Started
dotnet watch β Exited
dotnet watch β³ Waiting for a file to change before restarting dotnet...
On certain console hosts those characters can come out garbled π. To avoid seeing garbled characters, set this variable to 1 or true.
DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSERβ set to1ortrueand dotnet watch won't launch or refresh browsers for web apps that havelaunchBrowserconfigured inlaunchSettings.json.DOTNET_WATCH_SUPPRESS_MSBUILD_INCREMENTALISMβ by default dotnet watch optimizes the build by skipping certain operations, like running restore or re-evaluating the set of watched files on every file change. Set this variable to1ortrueand all those optimizations get disabled. periodt.DOTNET_WATCH_SUPPRESS_STATIC_FILE_HANDLINGβ set to1ortrueand dotnet watch stops doing special handling for static content files. It also sets the MSBuild propertyDotNetWatchContentFilestofalse.DOTNET_WATCH_RESTART_ON_RUDE_EDITβ set to1ortrueand dotnet watch will always restart on rude edits instead of asking you. no more "are u sure" texts, it just goes.
π¦ Files watched by default π¦
dotnet watch watches all items in the Watch item group in the project file. By default that group includes every item in the Compile and EmbeddedResource groups. It also scans the entire graph of project references and watches all files within those projects. obsessed with the thoroughness honestly.
By default, the Compile and EmbeddedResource groups include all files matching these glob patterns:
**/*.cs*.csproj**/*.resx- Content files in web apps:
wwwroot/**
By default, .config and .json files don't trigger a dotnet watch restart, because the configuration system has its own mechanisms for handling configuration changes. it's giving "i handle my own business".
Files can be added to the watch list or removed from it by editing the project file. You can name files individually or use glob patterns.
π Watch additional files π
You can watch more files by adding items to the Watch group. For example, this markup extends that group to include JavaScript files:
<ItemGroup>
<Watch Include="**\*.js" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
</ItemGroup>
π Ignore specified files π
dotnet watch will ignore Compile and EmbeddedResource items that have the Watch="false" attribute, like this:
<ItemGroup>
<Compile Update="Generated.cs" Watch="false" />
<EmbeddedResource Update="Strings.resx" Watch="false" />
</ItemGroup>
It'll also ignore project references that have the Watch="false" attribute, like this:
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" Watch="false" />
</ItemGroup>
β¨ Advanced configuration β¨
dotnet watch performs a design-time build to find the items to watch. When that build runs, dotnet watch sets the property DotNetWatchBuild=true. You can use that property like this:
<ItemGroup Condition="'$(DotNetWatchBuild)'=='true'">
<!-- only included in the project when dotnet-watch is running -->
</ItemGroup>
π₯ Hot Reload π₯
Starting in .NET 6 SDK, dotnet watch includes support for hot reload. Hot reload is a feature that lets you apply changes to a running app without having to rebuild and restart it. The changes can be to code files or to static assets like stylesheet files and JavaScript files. This feature streamlines the local development experience, because it gives you immediate feedback when you modify your app. main character energy, genuinely.
For information about app types and .NET versions that support hot reload, see Supported .NET app frameworks and scenarios.
π Rude edits π
When a file is modified, dotnet watch determines if the app can be hot reloaded. If it can't be hot reloaded, the change is called a rude edit, and dotnet watch asks if you want to restart the app:
dotnet watch β Unable to apply hot reload because of a rude edit.
β Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?
- Yes: Restarts the app.
- No: Leaves the app running without the changes applied.
- Always: Restarts the app and doesn't prompt anymore for rude edits.
- Never: Leaves the app running without the changes applied and doesn't prompt anymore for rude edits.
For information about what kinds of changes are considered rude edits, see Edit code and continue debugging and Unsupported changes to code.
To disable hot reload when you run dotnet watch, use the --no-hot-reload option, like this:
.NET CLI dotnet watch --no-hot-reload
π EXAMPLES π
- Run
dotnet runfor the project in the current directory whenever source code changes:
dotnet watch
Or:
dotnet watch run
- Run
dotnet testfor the project in the current directory whenever source code changes:
dotnet watch test
- Run
dotnet run --project ./HelloWorld.csprojwhenever source code changes:
dotnet watch run --project ./HelloWorld.csproj
- Run
dotnet run -- arg0for the project in the current directory whenever source code changes:
dotnet watch run -- arg0
Or:
dotnet watch -- run arg0
π«Ά SEE ALSO π«Ά
- Tutorial: Develop ASP.NET Core apps using a file watcher
- Hot reload in Visual Studio
- Hot reload supported apps
- Hot reload supported code changes
- Hot reload test execution
- Hot reload support for ASP.NET Core
okay bestie that's the whole page, we made it to the end π this cutie is from the dotnet-watch(1) manual, dated 2025-10-30. go forth and hot reload responsibly, you've got this π
π¦ where this page comes from
- alpine 3.24: dotnet-doc 10.0.303-r2 Β· MIT
- centos-stream 10: dotnet-host 11.0.0~rc.2.26504.105-0.10.el10 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- centos-stream 9: dotnet-host 11.0.0~rc.2.26504.105-0.11.el9 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 43: dotnet-host 10.0.12-1.fc43
- fedora 43: dotnet-host 11.0.0~rc.1.26425.128-0.10.fc43 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 44: dotnet-host 10.0.12-1.fc44
- fedora 44: dotnet-host 10.0.4-1.fc44 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- fedora 44: dotnet-host 11.0.0~rc.1.26425.128-0.12.fc44 Β· 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
- nixpkgs unstable: dotnet-vmr 11.0.0-rc.3
- ubuntu noble: dotnet-host-10.0 10.0.12-0ubuntu1~24.04.1
- ubuntu questing: dotnet-host-10.0 10.0.9-0ubuntu1~25.10.1
- ubuntu resolute: dotnet-host-10.0 10.0.12-0ubuntu1~26.04.1
- ubuntu resolute: dotnet-host-10.0 10.0.5-0ubuntu1 Β· MIT
- ubuntu stonking: dotnet-host-10.0 10.0.12-0ubuntu2 Β· MIT
- ubuntu stonking: dotnet-host-11.0 11.0.0~rc1-0ubuntu1 Β· MIT
- ubuntu stonking: dotnet-host-11.0 11.0.0~rc3-0ubuntu1~26.10.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms