This is not a question. Just wanted to share how I managed to finally debug .net core projects in Visual Studio after having the error in the title. I tried many many suggestions, but each time I tried to debug a .net core project - even a completely new Azure function of HTTP trigger template (V2) - I got the error that System.Runtime Version=4.2.1.0 is missing. First, I noticed that the new project was targeting .net standard. I changed it to .net core, so my .csproj file looked like that:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I tried adding
<PropertyGroup>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>
and
<PackageReference Include="System.Runtime" Version="4.3.1" />
to the .csproj file but that didn't help either.
I even tried to uninstall VS 2017 and VS 2019 and all .net core packages, and re-install them. But still no luck. Then I came to a conclusion that is has to do with my machine - some data has to be corrupted. Microsoft store data for .net core on the user's "hidden" %APPDATA% folder:
C:\Users\<USERNAME>\AppData\Local\AzureFunctionsTools\
Apparently, mine was missing quite a lot of data. About 300 MB instead of ~700. I guess that the slow internet connection I got in our offices has to do with it.
I found this article: https://github.com/Azure/azure-functions-host/issues/3759 soninaren, mentions the steps he did, and also provides a source for undamaged AzureFunctionsTools templates: https://github.com/soninaren/Workarounds/releases/download/1.0.0/AzureFunctionsTools.zip
Just unzip, Open each manifest.json file you find in there and replace the username in the tag TemplatesDirectory so it will point to your username folder. Then, delete your AzureFunctionsTools folder (C:\Users\<USERNAME>\AppData\Local\AzureFunctionsTools\) and copy the edited zip content instead.
Voila, you should be able to debug .net core projects and your new Azure function projects will initially target .net core.
Hope this helps, Ron