Skip to content

dotnet watch with hot reload reloads app when file added to bin #55952

Open

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running an app with dotnet watch run (hot reload enabled), the app will restart if a .cs file is added to the bin directory.

I know, it seems strange and wrong that a .cs file would be added to the bin directory, especially while it's running, but here's my situation:
My app includes a Nuget package Weasyprint.Wrapped that is a wrapper for a command line tool for html to pdf file generation. I don't know the details of what or why, but it is generating some files the first time it runs. Some of those files happen to have a .cs extension. They are not C# files, but happen to have the same extension. When Hot Reload is enabled, it detects a new .cs file has been created and restarts the app making it impossible to generate a pdf.

Running dotnet watch --list does not list anything in the bin directory. Editing an existing .cs file in the bin directory does not seem to be recognized as an edit (rude or otherwise). It only seems to recognize when a file has been added.

I also tried adding this to the .csproj:

<ItemGroup>
    <Watch Remove="bin/**/*.cs"/>
</ItemGroup>

It didn't help. I assume this is because it would only remove files from the initial watch list, which doesn't include files in the bin directory anyway.

Expected Behavior

Hot Reload should ignore new files in the bin directory. Failing that, I would have expected it to respect the <Watch Remove="">.

Steps To Reproduce

Create a new .NET 8 project from template. I used the "Web API" template.

Run dotnet watch run.

Copy any .cs file into /bin/Debug/net8.0. It can be empty or have any contents.

The following log is displayed and the app is restarted:

dotnet watch ⌚ New file: .\bin\Debug\net8.0\New.cs. Rebuilding the application.

It does not even present the "rude edit" message and options, it just restarts.

Exceptions (if any)

No response

.NET Version

8.0.300

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPIfeature-hot-reloadThis issue is related to the Hot Reload feaature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions