从 Visual Studio 连同 class 库部署 azure 函数

deploy azure function from Visual Studio along with class library

我有使用 visual studio 开发的 azure 函数,这个函数使用外部 class 库,而且这个函数有一些包。当我部署到 azure 函数应用程序和 运行 函数时,M 收到错误 500 内部服务器错误。

我还需要部署 class 库和包吗?如果是如何部署?

请帮我解决这个问题

  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Extensions.Http;
  using Microsoft.AspNetCore.Http;
  using Microsoft.Extensions.Logging;
  using Newtonsoft.Json;
 using IronPython.Hosting;//for DLHE
 using Microsoft.Scripting.Hosting;//provides scripting abilities comparable to batch files
using System.Diagnostics;
using IronPython.Compiler;
using System.Text;
using Microsoft.Scripting;
using DatasetLibrary;
using System.Data;

 namespace ExecutePyCode
   {
public static class Function1
{
    [FunctionName("Function1")]
    public static int Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string name = req.Query["name"];

        int result = 0;

        var engine = Python.CreateEngine();
        var scope = engine.CreateScope();
        //try
        //{

        var compilerOptions = (PythonCompilerOptions)engine.GetCompilerOptions();
        //compilerOptions.Module = IronPython.Runtime.ModuleOptions.co
        //ErrorSink errorSink = null;
        //ErrorListener errorListener = new ErrorSinkProxyListener(errorSink);
        //var scriptSource = engine.CreateScriptSourceFromFile(@"C:\Nidec\PythonScript\download_nrlist.py", Encoding.UTF8, Microsoft.Scripting.SourceCodeKind.File);
        //var compiledCode = scriptSource.Compile();
        //compiledCode.Execute(scope);
        //engine.ExecuteFile(@"C:\Nidec\PythonScript\download_nrlist.py", scope);

        //get function and dynamically invoke
        //var calcAdd = scope.GetVariable("CalcAdd");
        //result = calcAdd(34, 8); // returns 42 (Int32)
     
       //get values from external class library
        DatasetValues datasetValues = new DatasetValues();
        DataTable dt = datasetValues.GetDatasetValues();
        for (int i = 0; i <= dt.Rows.Count - 1; i++)
        {
            for (int j = 0; j <= dt.Columns.Count - 1; j++)
            {
                Console.WriteLine(dt.Rows[i][j]);

            }
        }

        return result;
    }
}

}

500错误对解决这个问题没有帮助,需要查看azure函数的具体错误。您可以使用 application insights 获取详细信息错误。该功能必须配置相应的应用程序洞察才能在门户上查看日志。

因此您需要像这样为您的函数应用程序配置应用程序见解:

然后您的函数应用程序将重新启动。

当然你也可以去kudu查看:

首先,进入高级工具,然后点击'GO',

然后进入kudu后,点击Debug Console -> CMD -> LogFiles -> Application -> Functions -> yourtriggername。您会在那里找到日志文件。

如果你是基于linuxOS,进入kudu后,直接点击'log stream'(linux消费计划不支持)。

项目的库和包在 project.json 中定义,并在将函数部署到 Azure 时自动安装。