Azure函数function.json使用不正确的scriptFile路径生成

时间:2017-11-18 08:39:37

标签: azure azure-functions

我终于设法让我的function.json文件生成大部分正确的属性。我仍然苦苦挣扎的唯一问题是scriptFile路径如果设置为错误的值。

使用值“bin / MyFunctions.dll”而不是“../bin/MyFunctions.dll”生成它。无论我是构建还是发布,都会发生

当我尝试运行脚本主机时,我收到错误:

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.

手动将值更改为“../bin/MyFunctions.dll”可解决此问题。

csproj文件

<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": ""
    }
}

这是我拥有的唯一4个文件。 dotnet build / publish产生一个Echo / function.json文件,如下所示:

{
  "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 个答案:

答案 0 :(得分:1)

我发现了我认为是SDK函数生成器代码中的错误。我在这里提交了一个拉取请求,试图解决它:

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