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:
My .bat file
for /f "tokens=5" %%a in ('netstat -aon ^| findstr "7071"') do taskkill /f /pid %%a
exit 0
Settings in VS2022
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