Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
408 stars 169 forks source link

No HotReload for Azure Functions VS Code Tooling #835

Open anujb opened 2 years ago

anujb commented 2 years ago

For issues with the Functions Visual Studio tooling, provide detailed steps to reproduce, including details about your environment (OS, VS version, etc)

Azure Functions Tooling using the C# .NET 6 isolated process function does not support the hot reload capability by default. I tried using the hot reload capability by adding a custom build target recommended here:

https://github.com/Azure/azure-functions-core-tools/issues/1239#issuecomment-669018902

But the reload on average 5 seconds, which is a poor inner loop experience.

Ved2806 commented 2 years ago

Hi @anujb Thank you for the feedback. We will discuss this internally and let you know about the findings. Thanks.

justinmchase commented 2 years ago

I was able to solve this by adding this to my csproj...

  <Target Name="RunFunctions" >
    <Exec Command="func host start" />
  </Target>

And then run

dotnet watch msbuild -t:RunFunctions
mdddev commented 2 years ago

I was able to solve this by adding this to my csproj...

  <Target Name="RunFunctions" >
    <Exec Command="func host start" />
  </Target>

And then run

dotnet watch msbuild -t:RunFunctions

Hi, this is the workaround the OP referenced above. It basically stops/restarts the process automatically and does not inject changes in the running process, which hot reload is supposed to do.

y2kbugger commented 1 year ago

@fabiocav Is the problem here that the dotnet worker is not compiling using dotnet watch / dotnet build and instead accesses MSBuild directly?

$ func start
MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.

And it almost seems like it's going to work just by running the usually dotnet watch

$ dotnet watch
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
  💡 Press "Ctrl + R" to restart.
dotnet watch 🔧 Building...
  Determining projects to restore...
  All projects are up-to-date for restore.
  NutritionFlockDataApi -> C:\Users\xxx\devel\xxx\backend-functionapp\bin\Debug\net7.0\MyApp.dll
  Determining projects to restore...
  Restored C:\Users\zkohler\AppData\Local\Temp\bflo3fox.e01\WorkerExtensions.csproj (in 1.14 sec).
  WorkerExtensions -> C:\Users\zkohler\AppData\Local\Temp\bflo3fox.e01\buildout\Microsoft.Azure.Functions.Worker.Extensions.dll
dotnet watch 🚀 Started
Unhandled exception. System.InvalidOperationException: The gRPC channel URI 'http://:0' could not be parsed.
   at Microsoft.Extensions.DependencyInjection.GrpcServiceCollectionExtensions.<>c.<AddGrpc>b__1_3(IServiceProvider p) in D:\a\_work\1\s\src\DotNetWorker.Grpc\GrpcServiceCo
y2kbugger commented 1 year ago

Also the workarounds don't work when combined with the Static Web App toolkit https://azure.github.io/static-web-apps-cli/docs/cli/swa-start

y2kbugger commented 1 year ago

https://github.com/Azure/azure-functions-core-tools/blob/bb8c53ef90183580c4c4853044e1cfe937dc8553/src/Azure.Functions.Cli/Helpers/DotnetHelpers.cs#L162-L178

Seems like the core tools are written in a way that expect the build to terminate, no real easy fix I guess?

alastairs commented 11 months ago

I really hope this comes in with the updates planned for .NET 8. Hot reload is such a productivity boost. I haven't even been able to get the workaround to work with Functions v4 and .NET 8 preview 7 SDK.

dcaponi commented 9 months ago

Piling on as well. Hot reload is one of those things that would make the Dev Ex buttery smooth 🧈

mdddev commented 9 months ago

It has been 2 years now. Either I didn't catch it, or there was no clear statement that this in the pipeline or not possible to realize with the current core tools.

I wonder, since the C# Devkit was just GA'd, can we expect hot reload from this in the near future? Or will VS remain to be the only thing that supports hot reload with Azure functions?

jpdillingham commented 3 months ago

@justinmchase thanks for the workaround above, it worked nicely until we upgraded to .NET 8, and now it's broken with:

Unhandled exception. System.InvalidOperationException: The gRPC channel URI 'http://:' could not be parsed.

I've just started looking for a solution, and will report back if I find one. It seems like a problem loading config from somewhere.

eolamisan commented 1 month ago

Same issue for dotnet 8.0 @jpdillingham did you find a solution?

jpdillingham commented 1 month ago

@eolamisan unfortunately no, I sunk a few hours into it and didn't reach any conclusions.