Ultimate goal is I want to run a Function App locally for automated testing. I don't know how to do so without using func.exe
. Here is my attempt:
/// <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();
}
This fails with output
your worker runtime is not set. As of 2.0.1-beta.26 a worker runtime setting is required. Please run
func settings add FUNCTIONS_WORKER_RUNTIME <option>
or add FUNCTIONS_WORKER_RUNTIME to your local.settings.json Available options: dotnet, node, python, powershell%%%%%% %%%%%% @ %%%%%% @ @@ %%%%%% @@ @@@ %%%%%%%%%%% @@@ @@ %%%%%%%%%% @@ @@ %%%% @@ @@ %%% @@ @@ %% @@ %% %
Azure Functions Core Tools (2.6.666 Commit hash: 2ea98edb55cd2fc249765fcf3f5e30829c7c9932) Function Runtime Version: 2.0.12408.0 Application is shutting down...
When I run the same command through the console it succeeds with
your worker runtime is not set. As of 2.0.1-beta.26 a worker runtime setting is required. Please run
func settings add FUNCTIONS_WORKER_RUNTIME <option>
or add FUNCTIONS_WORKER_RUNTIME to your local.settings.json Available options: dotnet, node, python, powershell%%%%%% %%%%%% @ %%%%%% @ @@ %%%%%% @@ @@@ %%%%%%%%%%% @@@ @@ %%%%%%%%%% @@ @@ %%%% @@ @@ %%% @@ @@ %% @@ %% %
Azure Functions Core Tools (2.6.666 Commit hash: 2ea98edb55cd2fc249765fcf3f5e30829c7c9932) Function Runtime Version: 2.0.12408.0 [4/26/2019 2:29:18 PM] Starting Rpc Initialization Service. [4/26/2019 2:29:18 PM] Initializing RpcServer … … Now listening on: http://0.0.0.0:63819 Application started. Press Ctrl+C to shut down.