This error appeared with visual studio 2022 v17.12.0 after this update VS installed and forcing the Azure Functions Tools v4.0.6517 by default and based on Microsoft documentations
So we have to solution to solve this issue, the first one is to Update Microsoft.NET.Sdk.Functions nuget package to be 4.5.0 and this will solve the issue, but what if you don't want to update this package at all, then you will need to downgrade the version of Azure Core Tools, so the following steps explains how to do it