Why host.json not being copied to output in F# Azure Functions project?

Viewed 490

In simple F# Azure Functions project host.json not being copied to output in F# Azure Functions project (same local.settings.json) even if specified so in fsharp-azure-functions-signalr-problem.fsproj:

<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>

Same C# project have no such problem.

Example of my F# project you can git clone https://github.com/ed-ilyin/fsharp-azure-functions-signalr-problem.git

Without host.json file I have following error:

> 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.).
...
2 Answers

So manual copy to compiled folder can solve this problem. I have test the F#, it seems problem comes from your .fsproj file, the definition of host.json should look like this:

<Content Include="host.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

This work fine on my side.

None Include works too:

<None Include="host.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

The problem is tracked in this issue.

C# projects by default include all files via a wild card. Thats why Update works. In F# no files are included by default (because file order matters). So there is nothing to update.

Related