1
votes

I've finally managed to get my function.json file to generate with mostly the correct attributes. The only problem I'm still struggling with is that the scriptFile path if set to the wrong value.

It gets generated with a value of "bin/MyFunctions.dll" instead of "../bin/MyFunctions.dll". This happens whether I build or publish.

When I try and run the script host I get the error:

The following 1 functions are in error:
Echo: Invalid script file name configuration. The 'scriptFile' property is set to a file that does not exist.

Manually changing the value to "../bin/MyFunctions.dll" solves the issue.

csproj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <NoWarn>NU1701</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta3" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

EchoFunction.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using System.Linq;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace EchoFunctionNameSpace
{
    public class EchoFunction
    {
        [FunctionName("Echo")]
        public static IActionResult Run(
            [HttpTriggerAttribute(AuthorizationLevel.Anonymous, "get", Route = "name/{name}/sname/{sname}")] 
            HttpRequest req, TraceWriter log, string name, string sname)
        {
            log.Info("C# HTTP trigger function processed a request.");

            return new OkObjectResult($"Hello {name} {sname}");
        }
    }
}

host.json

{}

local.settings.json

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "AzureWebJobsDashboard": ""
    }
}

Those are the only 4 files I have. dotnet build/publish produces a file Echo/function.json that looks like this:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "route": "name/{name}/sname/{sname}",
      "methods": [
        "get"
      ],
      "authLevel": "anonymous",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": "bin/AzureFunctions.dll",
  "entryPoint": "EchoFunctionNameSpace.EchoFunction.Run"
}
1
That's odd. Show more details about your project setup.Mikhail Shilkov
Added more infoCraigt
Hmm, copy-pasted your files, but build/publish produce ../bin just fine. Are all 4 files in the same folder without subfolders?Mikhail Shilkov
Any chance that you don't have the latest tooling or NuGet packages? Check under Tools / Extensions and updates, and under NuGet for the project.David Ebbo
All four files are in the same folder with no subfolders. I'm using v1.0.6 of the SDK and 2.0.1-beta.21 of the cli tools. As far as I can tell they are the latest versions? Cant get to the bottom of this...Craigt

1 Answers

1
votes

I found what I believe to be a bug in the SDK functions generator code. I have submitted a pull request here to try and get it resolved:

https://github.com/Azure/azure-functions-vs-build-sdk/pull/143