Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/core/project-sdk/msbuild-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ Use the `DefaultItemExcludes` property to define glob patterns for files and fol
</PropertyGroup>
```

> [!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.
Expand Down
30 changes: 27 additions & 3 deletions docs/core/tools/dotnet-watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ More files can be watched by adding items to the `Watch` group. For example, the
</ItemGroup>
```

## 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
<ItemGroup>
Expand All @@ -200,14 +202,36 @@ More files can be watched by adding items to the `Watch` group. For example, the
</ItemGroup>
```

`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
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" Watch="false" />
</ItemGroup>
```

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
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);**/App_Data/**</DefaultItemExcludes>
</PropertyGroup>
```

Exclude multiple patterns by separating them with semicolons:

```xml
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);**/App_Data/**;**/temp/**;**/*.log</DefaultItemExcludes>
</PropertyGroup>
```

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:
Expand Down