我在 Visual Studio 2022 中调试 Azure 函数时遇到问题
我使用以下命令行创建了一个函数
func init queue-events --worker-runtime dotnet-isolated --target-framework net8.0
然后我使用此命令添加了一个 HttpTrigger
func new --template "Http Trigger" --name MyHttpTrigger
我测试了该功能,看看它是否会启动,并且它可以使用
func start
我现在想在 Visual Studio 2022 中调试我的函数项目,但是当我启动它时,我遇到了这个错误。 “没有与项目中指定的版本匹配的可用函数运行时”。不知道现在该怎么办。该函数通过命令行运行,但不在 Visual Studio 2022 中运行
我什至更新了 Visual Studio Azure 函数工具/模板
供参考
dotnet --list-sdks
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.214 [C:\Program Files\dotnet\sdk]
5.0.416 [C:\Program Files\dotnet\sdk]
7.0.409 [C:\Program Files\dotnet\sdk]
8.0.105 [C:\Program Files\dotnet\sdk]
8.0.300 [C:\Program Files\dotnet\sdk]
函数--版本
Azure Functions Core Tools
Core Tools Version: 4.0.5801 Commit hash: N/A +5ac2f09758b98257e728dd1b5576ce5ea9ef68ff (64-bit)
Function Runtime Version: 4.34.1.22669
Visual Studio 版本
Microsoft Visual Studio Community 2022 (2) (64-bit) - Current
Version 17.10.0
没有与项目中指定的版本匹配的可用函数运行时
%LocalAppData%\AzureFunctionsTools
文件夹来清除缓存的 Azure Functions 工具。Tools=>Options=>Projects & Solutions=>Azure functions
下安装更新:我已经使用您提到的命令创建了一个 dotnet 隔离的 azure 函数。
Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.9.7
Azure Functions Core Tools
Core Tools Version: 4.0.5801
Function Runtime Version: 4.34.1.22669
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>queue_events</RootNamespace>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
主机.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}