From b31204486cb10a844bce0b142118a234850574d3 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Tue, 29 Sep 2020 14:20:11 -0700 Subject: [PATCH] Add more locations to find func (#682) --- docs/recipes/azure_functions.md | 6 +--- docs/reference/schema.md | 2 +- src/Microsoft.Tye.Hosting/FuncFinder.cs | 40 ++++++++++++++++++++----- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/docs/recipes/azure_functions.md b/docs/recipes/azure_functions.md index 475438b1..b24266a1 100644 --- a/docs/recipes/azure_functions.md +++ b/docs/recipes/azure_functions.md @@ -11,11 +11,7 @@ To start, create an Azure Function project in a folder called `backend-function` - [Visual Studio](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio) - [Commandline](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-azure-function-azure-cli?tabs=bash%2Cbrowser&pivots=programming-language-csharp) -Next, you must have the [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash) through npm. By default, if you created an azure function through VSCode or Commandline, you will already have installed it. Otherwise, you can install the core tools by running: - -```bash -npm install -g azure-functions-core-tools@3 -``` +Next, you must have the [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash). You can install the core tools by installing the [standalone installer](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2) or through [npm](https://www.npmjs.com/package/azure-functions-core-tools). You can also specify a path to func by specifying `pathToFunc` for the azure function service. diff --git a/docs/reference/schema.md b/docs/reference/schema.md index dad266c5..6b700697 100644 --- a/docs/reference/schema.md +++ b/docs/reference/schema.md @@ -226,7 +226,7 @@ A path to a folder which contains an azure function project. #### `pathToFunc` (string) -An optional path to the Azure Functions host to be used instead of the default one installed by npm. +An optional path to the Azure Functions host to be used. ## Environment Variables diff --git a/src/Microsoft.Tye.Hosting/FuncFinder.cs b/src/Microsoft.Tye.Hosting/FuncFinder.cs index c69303ad..ef166a53 100644 --- a/src/Microsoft.Tye.Hosting/FuncFinder.cs +++ b/src/Microsoft.Tye.Hosting/FuncFinder.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -49,25 +50,50 @@ namespace Microsoft.Tye.Hosting private string? FindFuncForVersion(AzureFunctionRunInfo func) { - var npmFuncDllPath = GetFuncNpmPath(); - if (!File.Exists(npmFuncDllPath)) + var funcDllPath = FuncDllPath(); + if (!File.Exists(funcDllPath)) { - throw new FileNotFoundException("Could not find func installation. Please install the azure function core tools via: `npm install -g azure-functions-core-tools@3`"); + throw new FileNotFoundException("Could not find func installation. Please install the azure function core tools with the installer: " + + "https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local or `npm install -g azure-functions-core-tools@3`"); } - _logger.LogDebug("Using func for running azure functions located at {Func}.", npmFuncDllPath); - return npmFuncDllPath; + _logger.LogDebug("Using func for running azure functions located at {Func}.", funcDllPath); + return funcDllPath; } - private string GetFuncNpmPath() + private string FuncDllPath() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + var funcPathStandalone = Environment.ExpandEnvironmentVariables("%PROGRAMFILES%/Microsoft/Azure Functions Core Tools/func.dll"); + if (File.Exists(funcPathStandalone)) + { + return funcPathStandalone; + } + return Environment.ExpandEnvironmentVariables("%APPDATA%/npm/node_modules/azure-functions-core-tools/bin/func.dll"); } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + var funcPathStandalone = "/usr/lib/azure-functions-core-tools-3/func.dll"; + if (File.Exists(funcPathStandalone)) + { + return funcPathStandalone; + } + + return "/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll"; + } else { - return Environment.ExpandEnvironmentVariables("/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll"); + // For brew path, just find a folder that supports functions v3. + var funcDirectories = Directory.GetDirectories("/usr/local/Cellar/azure-functions-core-tools@3/"); + var funcPathStandalone = Path.Combine(funcDirectories.LastOrDefault() ?? "", "func.dll"); + if (File.Exists(funcPathStandalone)) + { + return funcPathStandalone; + } + + return "/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll"; } }