dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.48k stars 10.04k forks source link

dotnet watch run watches all files under wwwroot even with exclusion list #31141

Open kanadaj opened 3 years ago

kanadaj commented 3 years ago

Describe the bug

Running on .NET 5.0.201, dotnet watch run reloads every time a JS or CSS files is modified in wwwroot even though I have no configuration that would tell it to do so.

dotnet watch --list lists all files under wwwroot as well.

Adding

  <ItemGroup>
    <Watch Remove="wwwroot\**\*" />
  </ItemGroup>

doesn't help.

To Reproduce

I can reproduce the issue with a brand new project:

>dotnet new mvc
>dotnet watch --list
H:\RRL\Test\Controllers\HomeController.cs
H:\RRL\Test\Models\ErrorViewModel.cs
H:\RRL\Test\Program.cs
H:\RRL\Test\Startup.cs
H:\RRL\Test\Test.csproj
H:\RRL\Test\Views\Home\Index.cshtml
H:\RRL\Test\Views\Home\Privacy.cshtml
H:\RRL\Test\Views\Shared\Error.cshtml
H:\RRL\Test\Views\Shared\_Layout.cshtml
H:\RRL\Test\Views\Shared\_ValidationScriptsPartial.cshtml
H:\RRL\Test\Views\_ViewImports.cshtml
H:\RRL\Test\Views\_ViewStart.cshtml
H:\RRL\Test\wwwroot\css\site.css
H:\RRL\Test\wwwroot\favicon.ico
H:\RRL\Test\wwwroot\js\site.js
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-grid.min.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-grid.min.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.min.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.min.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap.min.css
H:\RRL\Test\wwwroot\lib\bootstrap\dist\css\bootstrap.min.css.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.js
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.js.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.min.js
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.min.js.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.js
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.js.map
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.min.js
H:\RRL\Test\wwwroot\lib\bootstrap\dist\js\bootstrap.min.js.map
H:\RRL\Test\wwwroot\lib\bootstrap\LICENSE
H:\RRL\Test\wwwroot\lib\jquery-validation-unobtrusive\jquery.validate.unobtrusive.js
H:\RRL\Test\wwwroot\lib\jquery-validation-unobtrusive\jquery.validate.unobtrusive.min.js
H:\RRL\Test\wwwroot\lib\jquery-validation-unobtrusive\LICENSE.txt
H:\RRL\Test\wwwroot\lib\jquery-validation\dist\additional-methods.js
H:\RRL\Test\wwwroot\lib\jquery-validation\dist\additional-methods.min.js
H:\RRL\Test\wwwroot\lib\jquery-validation\dist\jquery.validate.js
H:\RRL\Test\wwwroot\lib\jquery-validation\dist\jquery.validate.min.js
H:\RRL\Test\wwwroot\lib\jquery-validation\LICENSE.md
H:\RRL\Test\wwwroot\lib\jquery\dist\jquery.js
H:\RRL\Test\wwwroot\lib\jquery\dist\jquery.min.js
H:\RRL\Test\wwwroot\lib\jquery\dist\jquery.min.map
H:\RRL\Test\wwwroot\lib\jquery\LICENSE.txt

### Exceptions (if any)
N/A

### Further technical details

.NET SDK (reflecting any global.json): Version: 5.0.201 Commit: a09bd5c86c

Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support): Version: 5.0.4 Commit: f27d337295

.NET SDKs installed: 3.1.302 [C:\Program Files\dotnet\sdk] 3.1.402 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk] 5.0.101 [C:\Program Files\dotnet\sdk] 5.0.102 [C:\Program Files\dotnet\sdk] 5.0.103 [C:\Program Files\dotnet\sdk] 5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

ghost commented 3 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

pranavkm commented 3 years ago

You'll want to exclude Content items from being watched. Removing it doesn't quite work because they're not in the Watch item group during global evaluation:

<ItemGroup>
     <!-- exclude all Content items from being watched -->
    <Content Update="@(Content)" Watch="false" />
</ItemGroup>

I've added a note to our docs to include this snippet: https://github.com/dotnet/AspNetCore.Docs/pull/21858/files

kanadaj commented 3 years ago

@pranavkm This seems like an undocumented change as the documentation says: https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/tutorials/dotnet-watch.md#customize-files-list-to-watch

By default, dotnet-watch tracks all files matching the following glob patterns:

**/*.cs
*.csproj
**/*.resx

with no mention of Content files

pranavkm commented 3 years ago

Good catch. I've updated the PR to include this.

kanadaj commented 3 years ago

Since it's also a new thing (either introduced with 5.0 or after 5.0, not entirely sure whether it's a major version or a patch, only noticed it in the current version) I don't remember seeing it in any of the changelogs either, I'd probably note this change somewhere in the changelogs?

kanadaj commented 3 years ago

Just an update on this one since the other ticket was moved here and then closed; based on https://github.com/dotnet/sdk/pull/15405 and https://github.com/dotnet/aspnetcore/pull/27744 the addition of content files to watch was no meant to cause a full app recompilation but rather was done for browser link to reload CSS files. The app recompilation is likely an unintended, unwanted side effect, so rather than a documentation change, this seems to be a bug in need of fixing.

DesktopMan commented 3 years ago

Just an update on this one since the other ticket was moved here and then closed; based on dotnet/sdk#15405 and #27744 the addition of content files to watch was no meant to cause a full app recompilation but rather was done for browser link to reload CSS files. The app recompilation is likely an unintended, unwanted side effect, so rather than a documentation change, this seems to be a bug in need of fixing.

I've been evaluating this feature using the ASP.NET MVC template in version 5.0.301. Changes to site.css or site.js does not recompile the project, it only hot reloads the changed files as expected.

I am getting a JavaScript Uncaught TypeError: styleElement is null error in aspnetcore-browser-refresh.js when changing site.css though.

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.