diff --git a/docs/core/project-sdk/msbuild-props.md b/docs/core/project-sdk/msbuild-props.md index 622396efac6c6..3e6c2da7daa83 100644 --- a/docs/core/project-sdk/msbuild-props.md +++ b/docs/core/project-sdk/msbuild-props.md @@ -879,6 +879,9 @@ Use the `DefaultItemExcludes` property to define glob patterns for files and fol ``` +> [!NOTE] +> The `DefaultItemExcludes` property excludes files and folders from being watched by `dotnet watch`. For more information, see [Ignore specified folders and files from `dotnet watch`](/dotnet/core/tools/dotnet-watch#ignore-specified-files-and-folders). + ### DefaultItemExcludesInProjectFolder Use the `DefaultItemExcludesInProjectFolder` property to define glob patterns for files and folders in the project folder that should be excluded from the include, exclude, and remove globs. By default, folders that start with a period (`.`), such as *.git* and *.vs*, are excluded from the glob patterns. diff --git a/docs/core/tools/dotnet-watch.md b/docs/core/tools/dotnet-watch.md index 341907240728f..351ba4f8f8b1e 100644 --- a/docs/core/tools/dotnet-watch.md +++ b/docs/core/tools/dotnet-watch.md @@ -189,9 +189,11 @@ More files can be watched by adding items to the `Watch` group. For example, the ``` -## Ignore specified files +## Ignore specified files and folders -`dotnet watch` will ignore `Compile` and `EmbeddedResource` items that have the `Watch="false"` attribute, as shown in the following example: +Use the `Watch="false"` attribute to ignore specified files. Use the `DefaultItemExcludes` property to ignore folders or files from being watched. + +To prevent `dotnet watch` from watching files, use the `Compile` and `EmbeddedResource` items with the `Watch="false"` attribute, as shown in the following example: ```xml @@ -200,7 +202,7 @@ More files can be watched by adding items to the `Watch` group. For example, the ``` -`dotnet watch` will ignore project references that have the `Watch="false"` attribute, as shown in the following example: +`dotnet watch` ignores project references that have the `Watch="false"` attribute, as shown in the following example: ```xml @@ -208,6 +210,28 @@ More files can be watched by adding items to the `Watch` group. For example, the ``` +Starting in .NET 10, use the `DefaultItemExcludes` property to exclude entire folders or file patterns from being watched by `dotnet watch`. This approach is useful when you want to exclude files that aren't relevant to compilation or files that trigger unwanted restarts or reloads. + +For example, files in the `App_Data` folder of ASP.NET Core applications might change while the app runs, causing unnecessary page reloads. Exclude this folder from being watched: + +```xml + + $(DefaultItemExcludes);**/App_Data/** + +``` + +Exclude multiple patterns by separating them with semicolons: + +```xml + + $(DefaultItemExcludes);**/App_Data/**;**/temp/**;**/*.log + +``` + +The `DefaultItemExcludes` property affects all default item types, like `Compile` and `EmbeddedResource`. The `Watch="false"` attribute provides finer control over specific files or project references. + +For more information, see the [DefaultItemExcludes reference](../project-sdk/msbuild-props.md#defaultitemexcludes). + ## Advanced configuration `dotnet watch` performs a design-time build to find items to watch. When this build is run, `dotnet watch` sets the property `DotNetWatchBuild=true`. This property can be used as shown in the following example: