private string GetAmazonLambdaToolVersion() { // check if dotnet executable can be found var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { return(null); } // check if Amazon Lambda Tools extension is installed var result = ProcessLauncher.ExecuteWithOutputCapture( dotNetExe, new[] { "lambda", "tool", "help" }, workingFolder: null ); if (result == null) { return(null); } // parse version from Amazon Lambda Tools var match = Regex.Match(result, @"\((?<Version>.*)\)"); if (!match.Success) { return(null); } return(match.Groups["Version"].Value); }
private bool CheckDotNetLambdaToolIsInstalled() { // only run check once if (_dotnetLambdaToolVersionChecked) { return(_dotnetLambdaToolVersionValid); } _dotnetLambdaToolVersionChecked = true; // check if dotnet executable can be found var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { LogError("failed to find the \"dotnet\" executable in path."); return(false); } // check if AWS Lambda Tools extension is installed var result = ProcessLauncher.ExecuteWithOutputCapture( dotNetExe, new[] { "lambda", "tool", "help" }, workingFolder: null ); if (result == null) { // attempt to install the AWS Lambda Tools extension if (!ProcessLauncher.Execute( dotNetExe, new[] { "tool", "install", "-g", "Amazon.Lambda.Tools" }, workingFolder: null, showOutput: false )) { LogError("'dotnet tool install -g Amazon.Lambda.Tools' command failed"); return(false); } // latest version is now installed, we're good to proceed _dotnetLambdaToolVersionValid = true; return(true); } // check version of installed AWS Lambda Tools extension var match = Regex.Match(result, @"\((?<Version>.*)\)"); if (!match.Success || !VersionInfo.TryParse(match.Groups["Version"].Value, out var version)) { LogWarn("proceeding compilation with unknown version of 'Amazon.Lambda.Tools'; please ensure latest version is installed"); _dotnetLambdaToolVersionValid = true; return(true); } if (version.CompareTo(VersionInfo.Parse(MIN_AWS_LAMBDA_TOOLS_VERSION)) < 0) { // attempt to install the AWS Lambda Tools extension if (!ProcessLauncher.Execute( dotNetExe, new[] { "tool", "update", "-g", "Amazon.Lambda.Tools" }, workingFolder: null, showOutput: false )) { LogError("'dotnet tool update -g Amazon.Lambda.Tools' command failed"); return(false); } } _dotnetLambdaToolVersionValid = true; return(true); }