Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document How to Enable Hot Reloading Using dotnet run/watch #38036

Closed
RehanSaeed opened this issue Oct 25, 2021 · 15 comments
Closed

Document How to Enable Hot Reloading Using dotnet run/watch #38036

RehanSaeed opened this issue Oct 25, 2021 · 15 comments
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@RehanSaeed
Copy link
Contributor

Is your feature request related to a problem? Please describe.

It is not clear how to enable hot reloading using dotnet run or dotnet watch from a launchSettings.json file. The .NET blog mention that we should add the "hotReloadProfile": "aspnetcore" setting like so:

"Kestrel": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "hotReloadProfile": "aspnetcore"
  "launchBrowser": true,
  "launchUrl": "weatherforecast",
  "applicationUrl": "http://localhost:5093",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},

However, I also came across this PR which removes this need:

Then there is the question about how to enable the feature when using dotnet watch in a launchSettings.json file:

"Watch Kestrel (CTRL+F5)": {
  "commandName": "Executable",
  "executablePath": "dotnet",
  "workingDirectory": "$(ProjectDir)",
  "commandLineArgs": "watch",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},

It would also be nice to know if this affects IIS Express or WSL2

    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "graphql",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WSL 2": {
      "commandName": "WSL2",
      "launchBrowser": true,
      "launchUrl": "http:////localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_URLS": "http://localhost:5000",
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "distributionName": ""
    },

Describe the solution you'd like

I'd like to know how to enable the feature for both dotnet run and dotnet watch from a launchSettings.json file and have this documented somewhere.

@taha-ghadirian
Copy link
Contributor

taha-ghadirian commented Oct 25, 2021

Hello @RehanSaeed, There is still some problems with Dotnet hot reload.
If you have Dotnet 6 RC1 or higher (current version RC2), you can use (Dotnet watch --project .).
Dotnet watch command have some problems that need to be fixed as soon as it's possible. but for temporal ignoring errors, you should use --project PROJECTLOCATION flag.

NOTE: You don't need to edit launchSettings.json or any other settings if you are running on dotnet 6 preview6 or higher.

Wrong examples:
Dotnet watch
Dotnet watch run
Dotnet watch --project ./apps/client/ run

Correct examples:
Dotnet watch --project . (Dot means current location)
Dotnet watch --project ./apps/client

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/sdk Nov 2, 2021
@mkArtakMSFT mkArtakMSFT added area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) labels Nov 2, 2021
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
Looks like @taha-ghadirian answered this already on how to achieve what you're looking for. Closing, as there are no more actions pending here.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Nov 2, 2021
@ghost ghost added the Status: Resolved label Nov 2, 2021
@taha-ghadirian
Copy link
Contributor

taha-ghadirian commented Nov 3, 2021

Hello @mkArtakMSFT, I think we should consider it as a bug, because normally we just need to run dotnet watch command without --project . flag when we are in the same directory of the project.

Also dotnet watch command will fail when system goes to sleep. So we should restart system (Not restarting dotnet watch) to fix this issue.

@chhinsras
Copy link

chhinsras commented Nov 9, 2021

I use dotnet watch run or dotnet run inside Server project (Blazor Hosted). File changed detected but No hot reload change to apply , why?

I need to run Client project. but how can i run both Server and Client?

@taha-ghadirian
Copy link
Contributor

I use dotnet watch run or dotnet run inside Server project (Blazor Hosted). File changed detected but No hot reload change to apply , why?

Actually it's a bug in dotnet watch command, please run this command in Server project and use --project . flag.
This solution will fix that issue.

@chhinsras
Copy link

chhinsras commented Nov 9, 2021

I use dotnet watch run or dotnet run inside Server project (Blazor Hosted). File changed detected but No hot reload change to apply , why?

Actually it's a bug in dotnet watch command, please run this command in Server project and use --project . flag. This solution will fix that issue.

are you saying go to Server folder. then run dotnet watch --project ? will it run Client project as well?

image
I followed and NO client project wont have hot reload

@taha-ghadirian
Copy link
Contributor

Hello @chhinsras, Yes!
Open Server project, run Dotnet watch --project . or dotnet watch --project .\ProjectName.csproj or dotnet watch --project ProjectName.csproj one of this commands should work.

@taha-ghadirian
Copy link
Contributor

taha-ghadirian commented Nov 9, 2021

are you saying go to Server folder. then run dotnet watch --project ? will it run Client project as well?

image I followed and NO client project wont have hot reload

Can you run it again with -v flag? Then copy all logs for us, thanks :)

@chhinsras
Copy link

are you saying go to Server folder. then run dotnet watch --project ? will it run Client project as well?
image I followed and NO client project wont have hot reload

Can you run it again with -v flag? Then copy all logs for us, thanks :)

image

@taha-ghadirian
Copy link
Contributor

taha-ghadirian commented Nov 9, 2021

are you saying go to Server folder. then run dotnet watch --project ? will it run Client project as well?

Look at last line, it says: Watch: Hot reload capabilities: . but it should say: Watch: Hot reload capabilities: BASELINE..

please use this comment then check if it's fixed or not: dotnet watch --project .\Server.csproj -v
If it wouldn't fix, try changing your default browser to a new chrome browser (without any extension installed).

@chhinsras
Copy link

are you saying go to Server folder. then run dotnet watch --project ? will it run Client project as well?

Look at last line, it says: Watch: Hot reload capabilities: . but it should say: Watch: Hot reload capabilities: BASELINE..

please use this comment then check if it's fixed or not: dotnet watch --project .\Server.csproj -v If it wouldn't fix, try changing your default browser to a new chrome browser (without any extension installed).

I followed your recommendation. still no luck. Its not updating the UI

image

@jhulbertpmn
Copy link

Same issue here.

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/2 POST https://localhost:5001/_framework/blazor-hotreload application/json 2
watch : Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
watch : No hot reload changes to apply.
watch : Hot reload change handled in 839.5826ms.

@chhinsras
Copy link

in any workaround

@ceeol
Copy link

ceeol commented Nov 15, 2021

Tried all the different suggestions, and this was really a struggle.
I did manage to get hot reload working by creating the small template project by using exactly --project .\Server.csproj, and getting Baseline.
No luck with another project though, just getting "watch : Hot reload capabilities: ." This was earlier created with .Net 5, and I discovered there were upgrades. Finally got it to work. It needs to be more user friendly than this, though.

@chhinsras
Copy link

@ceeol

Still no luck tho. Really disappointed. how simple thing like this can't be working.

image

@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

6 participants