One of our developers is currently building an Azure Function app in.Net 6.0 using Visual Studio 2022 Preview on Windows 10.
The solution has several projects, 1 Azure Function and several class libraries. It fails to run with:
Metadata generation failed. Exit code: '-2147450750' Error: 'Failed to load the dll from [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\hostpolicy.dll], HRESULT: 0x800700C1An error occurred while loading required library hostpolicy.dll from [C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0]' DATA.Services.CompaniesQuery.Function C:\Users\r_ver.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\4.0.1\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets 37
Microsoft.NETCore.App is using version 6.0.1 and is listed until Solution Explorer in the Azure Function project in Dependencies > Frameworks > Microsoft.NETCore.App.
We have tried the following:
Reinstalling.Net 6 SDK
Reinstalled VS 2022 version 17.0.5
Laptop restart
Deleted contents of "C:\Users\someuser.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator" folder.
C:\Program Files\dotnet\shared\Microsoft.NETCore.App has folder for.Net Core 2.0.0 and 6.0.1
The error relates to 2.0.0 however no references are made to this in the project including csproj files.
Is a manual update required to the targets file? Currently not aware of any resolution to this.
I have tried in my environment and it works as expected,
To build an Azure Function app in .Net 6.0
using Visual Studio 2022
Preview(17.0.5) on Windows 10.
Below are the steps which i have followed:
Azure function core tools 4x
After that make sure that we have Azure function runtime v4 is available in .csproj
file as below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
OUTPUT:-
NOTE:-
When installing Azure function core tools version, make sure that we have installed only one core tool version on our computer.
.net 6 supports Azure function runtime version 4x only.
For more information please refer this Microsoft Documentation : Azure Functions runtime versions overview
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.