0

I have tried this and I get the following error

Port 7071 is unavailable. Close the process using that port, or specify another port using --port [-p].

There are various fixes for this to run the second function on a different port which I think work on pre .net 5 but they do not work on .net 5

Any ideas please?

Dave Amour
  • 155
  • 1
  • 13
  • Can you link to those fixes? So that we can look at them and maybe point out something you've missed? – Ian Kemp Aug 11 '21 at 08:25
  • Sure https://azurelessons.com/run-multiple-azure-functions-locally - scroll down to host start --pause-on-error --port 5860 is pretty much the only fixes I have found or slight variations of this – Dave Amour Aug 11 '21 at 13:00

3 Answers3

1

A rather trivial solution based on juunas' answer to the Run Azure Functions V3 (.NET 5) on a different port locally question that initially didn't work for me.
I was not able to start the function app on a port different from the default 7071 directly from Visual Studio 2019, but I managed to start it from the command prompt and then attach the debugger to the new dotnet.exe process.
Briefly:

  • open a command prompt and move to your function app Visual Studio project directory
  • as juunas pointed out in his answer, now .NET 5 starts the isolated process with dotnet func.dll host start, so you can start your function app on the 7073 port with the command: "%LOCALAPPDATA%\AzureFunctionsTools\Releases\3.28.0\cli_x64\func.dll" host start --port 7073
  • if you need it, you can attach the Visual Studio debugger from the Debug / Attach to process menu, looking for one of the dotnet.exe instances.

Obviously this is not an optimal solution because we are explicitly referring to a particular Functions version, but it's a pragmatic procedure to run and debug multiple Function projects locally.

  • Thanks for this. I have already considered this approach but its just not practical. I really need a way to do this from just clicking run in VS. If it can't be done, fair enough but I have to see if anyone knows. Thanks again. Also I might be working in scenarios where I have a dozen or more functions all running so even less practical. – Dave Amour Aug 17 '21 at 07:48
  • PS This doesn't work for me anyway - I get an error "Failed to launch functions process. The function process exited before launching the application". – Dave Amour Aug 18 '21 at 04:21
0

1. Configure a port for each of your function projects.

Refer to this link Setting different port for azure function

2. Start Debug with multiple projects in VS

How to start multiple projects in Visual Studio

Tuan
  • 893
  • 1
  • 9
  • 24
  • Thanks but doesn't work for me. Did you get this working yourself? – Dave Amour Aug 23 '21 at 04:27
  • PS - I also created a barebones solution with two Functions and that doesn't work with your suggestion. I think you have missed the point that your solution and many others may work for pre .net 5 but nor for .net 5. – Dave Amour Aug 23 '21 at 06:25
  • I have a project with multiple azure functions running with one click. But yes, prior net5. Was assuming it makes no difference. Can you describe what went wrong or provide your barebone code? – Tuan Aug 23 '21 at 07:22
  • Did you configure a different port for each of your functions? How does your config look like? – Tuan Aug 23 '21 at 07:25
  • A project with multiple azure functions is fine. That is not my scenario. My scenario is multiple Function projects. Ie 1 Solution with 2 projects in. Each project contains 1 Azure function. I have tried configuring different ports in multiple ways. None of them work. They all give the usual error message about port 7071 being used. – Dave Amour Aug 23 '21 at 11:29
  • How can I provide you with my barebones code? Ie which method do you prefer? you can create it in 2 minutes though. Just 1 solutiuon and 2 .net http Azure functions – Dave Amour Aug 23 '21 at 11:30
  • Best would be to push it to GitHub so others can also look at it. Understood, 1 Solution, 2 Azure function projects. meant the same. – Tuan Aug 23 '21 at 12:46
  • Publishing on Github will take some time to organise. I'll do it when I have time. – Dave Amour Aug 23 '21 at 13:37
0

This is a bug in VS2019. Fixed for VS2022 preview, but not in VS2019 so far.

https://developercommunity.visualstudio.com/t/Cant-debug-multiple-dotnet-5-Azure-Func/1505797#T-N1524939

Michel de Kok
  • 86
  • 1
  • 2