在简单的 F# Azure Functions 项目中,即使在 fsharp-azure-functions-signalr-problem.fsproj 中如此指定,host.json 也不会被复制到 F# Azure Functions 项目中的输出(相同的 local.settings.json):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<RootNamespace>fsharp_azure_functions_signalr_problem</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
</ItemGroup>
<ItemGroup>
<Compile Include="negotiate.fs" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
同一个C#项目没有这样的问题。
我的 F# 项目示例,您可以git clone https://github.com/ed-ilyin/fsharp-azure-functions-signalr-problem.git
如果没有 host.json 文件,我会出现以下错误:
> func start
...
Microsoft.Azure.WebJobs.Host: Error indexing method 'negotiate'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'connectionInfo' to type SignalRConnectionInfo. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
...
最佳答案
所以手动复制到编译文件夹可以解决这个问题。我已经测试了 F#,看来问题来自你的 .fsproj 文件,host.json 的定义应该如下所示:
<Content Include="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
这对我来说效果很好。
关于azure - 为什么 host.json 没有被复制到 F# Azure Functions 项目中的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60501474/