dotnet-watch on project doesn't detect new files
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Describe the bug
`dotnet-watch` on a project as described [“Develop ASP.NET Core apps using a file watcher”](https://github.com/aspnet/Docs/blob/a7609c3d5af84f9391f24dad02a00b660d849aa4/aspnetcore/tutorials/dotnet-watch.md#custom-watch-projects), and specifically the section [Run tests using `dotnet watch`](https://github.com/aspnet/Docs/blob/a7609c3d5af84f9391f24dad02a00b660d849aa4/aspnetcore/tutorials/dotnet-watch.md#run-tests-using-dotnet-watch), does not detect additions of new file.
### To Reproduce
Create a directory for the project:
mkdir DotNetWatcherIssueDemo
Change to the project directory:
cd DotNetWatcherIssueDemo
Initialize it with a new test project:
dotnet new nunit
Launch VS Code on the directory containing the test project:
code .
Ask to watch project and run tests on changes:
dotnet watch test
At this stage, you should see the output:
```
watch : Started
Build started, please wait...
Build completed.
Test run for A:\temp\DotNetWatchIssueDemo\bin\Debug\netcoreapp2.2\DotNetWatchIssueDemo.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.9364 Seconds
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
```
Now add a new test to `UnitTest1.cs`:
```diff
diff --git a/UnitTest1.cs b/UnitTest1.cs
index 66ec70e..f6406e7 100644
--- a/UnitTest1.cs
+++ b/UnitTest1.cs
@@ -14,5 +14,11 @@ namespace Tests
{
Assert.Pass();
}
+
+ [Test]
+ public void Test2()
+ {
+ Assert.Pass();
+ }
}
}
\ No newline at end of file
```
`dotnet watch` will pick up the change, run _two_ tests successfully and continue to watch for further file changes:
```
watch : Started
Build started, please wait...
Build completed.
Test run for A:\temp\DotNetWatchIssueDemo\bin\Debug\netcoreapp2.2\DotNetWatchIssueDemo.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Total tests: 2. Passed: 2. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 0.9698 Seconds
watch : Exited
watch : Waiting for a file to change before restarting dotnet...
```
In a separate shell, `cd` into the project directory and add a new test file:
dotnet new nunit-test -n UnitTest2 -o .
### Expected behavior
At the last step, I expected `dotnet watch` to pick up the new file change, build and re-run all tests, but it does nothing.
It seems that it builds a static list of files and only watches those for changes. If I touch/force-save the project file (`DotNetWatcherIssueDemo.csproj`) then `dotnet watch` detects the change, re-builds the watch list and detects changes to the added file, but again, not for any new file added thereafter.
### Additional context
Output of `dotnet --info`:
```
.NET Core SDK (reflecting any global.json):
Version: 2.2.101
Commit: 236713b0b7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.101\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
1.1.8 [C:\Program Files\dotnet\sdk]
1.1.9 [C:\Program Files\dotnet\sdk]
1.1.10 [C:\Program Files\dotnet\sdk]
1.1.11 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
```
/cc @natemcmaster
Contributor guide
Assessment
This issue has not been assessed yet.