以编程方式启动Function App失败,没有描述性输出

时间:2019-04-26 15:30:17

标签: c# visual-studio azure azure-functions azure-functions-runtime

最终目标是我想在本地运行Function App进行自动化测试。不使用func.exe,我不知道该怎么做。这是我的尝试:

    /// <summary>
    /// Setup environment for running integration tests on MyApp APIs
    /// </summary>
    /// <param name="testContext"></param>
    [ClassInitialize]
    public static void RunFileHubLocally(TestContext testContext)
    {
        // Do the programmatic equivalent of right-click "Debug -> Start new instance" on API.
        // This uses Azure Functions Core CLI to deploy the Function App locally.
        azureFunctionsCliShell = new Process();

        azureFunctionsCliShell.StartInfo.UseShellExecute = false;
        azureFunctionsCliShell.StartInfo.RedirectStandardOutput = true;
        azureFunctionsCliShell.StartInfo.CreateNoWindow = true;

        azureFunctionsCliShell.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\lib\azure-functions-core-tools\func.exe"); ;
        var fileInTargettedWorkingDirectory = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\..\..\..\src\MyApp.Api\bin\Debug\netcoreapp2.1\host.json"));
        azureFunctionsCliShell.StartInfo.WorkingDirectory = fileInTargettedWorkingDirectory.Directory.FullName;
        int port = FreeTcpPort();
        azureFunctionsCliShell.StartInfo.Arguments = $"host start --port {port}";
        apiUrl = $"http://localhost:{port}/api";
        azureFunctionsCliShell.Start();

        // Wait for "Application started", the line in the output that indicates the
        // application is listening to the port
        const string specialPhrase = "Application started";
        for ( ; ; )
        {
            string line = azureFunctionsCliShell.StandardOutput.ReadLine();

            Console.WriteLine(line);

            if (line.Contains(specialPhrase))
            {
                break;
            }

            if (azureFunctionsCliShell.StandardOutput.EndOfStream)
            {
                throw new Exception($"Output did not contain special phrase '{specialPhrase}'. Last line: '{line}'.");
            }
        }

        // Hold instance of HttpClient to be disposed of during cleanup
        httpClient = new HttpClient();
    }

此操作失败,输出

  

您的工作程序运行时未设置。从2.0.1-beta.26开始,工作程序运行时   需要设置。请运行func settings add FUNCTIONS_WORKER_RUNTIME <option>或将FUNCTIONS_WORKER_RUNTIME添加到   您的local.settings.json可用选项:dotnet,node,python,   Powershell

              %%%%%%
             %%%%%%
        @   %%%%%%    @
      @@   %%%%%%      @@
   @@@    %%%%%%%%%%%    @@@
 @@      %%%%%%%%%%        @@
   @@         %%%%       @@
     @@      %%%       @@
       @@    %%      @@
            %%
            %
     

Azure函数核心工具(2.6.666提交哈希:   2ea98edb55cd2fc249765fcf3f5e30829c7c9932)函数运行时版本:   2.0.12408.0应用程序正在关闭...

当我通过控制台运行同一命令时,它会成功

  

您的工作程序运行时未设置。从2.0.1-beta.26开始,工作程序运行时   需要设置。请运行func settings add FUNCTIONS_WORKER_RUNTIME <option>或将FUNCTIONS_WORKER_RUNTIME添加到   您的local.settings.json可用选项:dotnet,node,python,   Powershell

              %%%%%%
             %%%%%%
        @   %%%%%%    @
      @@   %%%%%%      @@
   @@@    %%%%%%%%%%%    @@@
 @@      %%%%%%%%%%        @@
   @@         %%%%       @@
     @@      %%%       @@
       @@    %%      @@
            %%
            %
     

Azure函数核心工具(2.6.666提交哈希:   2ea98edb55cd2fc249765fcf3f5e30829c7c9932)函数运行时版本:   2.0.12408.0 [4/26/2019 2:29:18 PM]启动Rpc初始化服务。 [2019/4/26 2:29:18 PM]初始化RpcServer   …   …   现在收听:http://0.0.0.0:63819应用程序已启动。按Ctrl + C   关闭。

1 个答案:

答案 0 :(得分:0)

func CLI本身就是Azure Functions Runtime的包装。

您可以代替docker route,而不必像func CLI那样编写另一个包装,它可以像在Azure本身上运行它一样近。

使用docker,您将大大简化整体CI管道,因为大多数CI服务器本机都支持使用容器运行工作流。

此外,如果您愿意,也可以将这些容器也部署到Azure。 但是 请注意,Consumption Plan尚不支持Linux,因此您将拥有改为使用Linux App Service Plan