Visual Studio - Kill the existing process using the Azure Functions Port and attach to the running function at runtime

krishna572 886 Reputation points
2023-02-19T10:57:49.4133333+00:00

My Scenario is:

I'm running one function locally which is using the port 7071 by VS 2022.

When I launch another function, it is saying that port 7071 is unavailable, using by another process.

I can define alternative port on local.settigns.json

But What I want to achieve here is, When I launch the another function locally in VS IDE, it should close/destroy the existing process using by the port 7071 and attach that port to current launching function in runtime?

Is this Possible, How.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET .NET Runtime
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-02-22T08:07:14.2766667+00:00

    Hi @Vaishnavi

    Thanks for your patience. After investigating, I find a workaround.

    I found that when a project uses port 7071, another project needs to be rebuilt or built before the following script can be executed. Sometimes we can run directly by clicking Run, but more often it is not. The reason may be that the current project has not changed, and VS2022 will not compile. Like the pre-build name in our workaround, the script will only be executed when the build needs to be executed.

    Official doc : How to: Specify build events (C#)

    My Test Result:

    Animation

    My .bat file

    for /f "tokens=5" %%a in ('netstat -aon ^| findstr "7071"') do taskkill /f /pid %%a

    exit 0

    User's image

    Settings in VS2022

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Jason Pan

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.