NOP*_*MOV 19 c# azure .net-core azure-functions
我正在尝试将在 .NET 3.1 上完美运行的 Azure Function 迁移到 .NET 5。我遵循了 Microsoft 的 GitHub 指南,但仍然无法让它在本地运行或调试(甚至没有尝试发布到 Azure)。
我收到此错误:
[2021-09-05T09:49:33.066Z] A host error has occurred during startup operation 'bb37a6db-b6f4-4396-bb9b-cb5ae0bba387'.
[2021-09-05T09:49:33.067Z] Microsoft.Azure.WebJobs.Script: Did not find functions with language [dotnet-isolated].
Run Code Online (Sandbox Code Playgroud)
并且正在引发此异常:
这是我的 Program.cs:
static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration(c =>
{
c.AddCommandLine(args);
})
.ConfigureServices(s =>
{
s.AddLogging();
})
.Build();
await host.RunAsync();
}
Run Code Online (Sandbox Code Playgroud)
这是我的项目文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<UserSecretsId>76d0a5ed-221b-4b35-8ff4-3ee33d393196</UserSecretsId>
<OutputType>Exe</OutputType>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<None Remove="global.json" />
</ItemGroup>
<ItemGroup>
<Content Include="global.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我的 local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "HIDDEN",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
Run Code Online (Sandbox Code Playgroud)
我的主机.json:
{
"logging": {
"fileLoggingMode": "always",
"logLevel": {
//"QueueWorkers.EmailQueueWorker": "Trace",
//"QueueWorkers.EmailQueueWorker.EmailQueueWorker": "Trace",
"default": "Information",
"Function": "Trace",
"Host.Results": "Error",
"Host.Aggregator": "Trace"
},
"applicationInsights": {
//"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
},
"console": {
"isEnabled": "true"
}
},
"Values": {
"AzureWebJobsStorage": "HIDDEN",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"extensions": {
"queues": {
"maxDequeueCount": 5,
"maxPollingInterval": "00:00:02"
}
},
"version": "2.0"
}
Run Code Online (Sandbox Code Playgroud)
谢谢
pin*_*ing 42
在 Azure 中导航到您的函数,然后在“设置”->“配置”部分中更改应用程序设置:
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
Run Code Online (Sandbox Code Playgroud)
Dwa*_*wne 26
在尝试将项目从 .net 5 迁移到 .net 6 功能时,在 Visual Studio 2022 中遇到了类似的问题...
一直告诉我“Microsoft.Azure.WebJobs.Script:没有找到语言[dotnet-isolated]的函数”
1)我丢失了:Program.cs
using Microsoft.Azure.Functions.Worker.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
namespace Main.Function
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
}
}
Run Code Online (Sandbox Code Playgroud)
2) 编辑 .csproj > 在 ItemGroup 下...
消除:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
Run Code Online (Sandbox Code Playgroud)
用。。。来代替
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
Run Code Online (Sandbox Code Playgroud)
3)确保OutputType设置为exe
<OutputType>Exe</OutputType>
Run Code Online (Sandbox Code Playgroud)
4)卸载项目并重新加载(构建前删除bin和obj文件夹)
好吧,仍然无法直接从 VS 2019 启动和调试,但如果从 CLI 启动并且调试正常,功能确实可以工作。
Debugger.Launch();
到Program.cs(Main方法的第一行)<LangVersion>preview</LangVersion>
的 csproj 中有(位于 TargetFramework 之后)。这条缺失的行实际上是阻止我的函数工作的关键差异。谢谢