When I came across this error in devops build pipelines, I initially though that there must have been some uninted change done by visual studio to project file which causes this error. However after checking diff it was clear that there were absolutely no changes in the two commits apart from whitespaces.
Thus reason for this error became a suspense until I stumbled across this post
https://gert-cominotto.be/2019/02/18/azure-devops-functions-build-fails-the-project-was-restored-using-microsoft-netcore-app-version-1-0-0-but-with-current-settings-version-2-1-6-would-be-used-instead/
It basically says that the error is caused by Nuget Restore task in Azure pipeline which always uses dot net core 1.0.0.
And the solution is to use dotnet restore task instead of Nuget restore task.
Thus reason for this error became a suspense until I stumbled across this post
https://gert-cominotto.be/2019/02/18/azure-devops-functions-build-fails-the-project-was-restored-using-microsoft-netcore-app-version-1-0-0-but-with-current-settings-version-2-1-6-would-be-used-instead/
It basically says that the error is caused by Nuget Restore task in Azure pipeline which always uses dot net core 1.0.0.
And the solution is to use dotnet restore task instead of Nuget restore task.