public static async Task <LayerPackageInfo> LoadLayerPackageInfos(IToolLogger logger, IAmazonLambda lambdaClient, IAmazonS3 s3Client, IEnumerable <string> layerVersionArns)
        {
            var info = new LayerPackageInfo();

            if (layerVersionArns == null || !layerVersionArns.Any())
            {
                return(info);
            }

            logger.WriteLine("Inspecting Lambda layers for runtime package store manifests");
            foreach (var arn in layerVersionArns)
            {
                try
                {
                    var p = ParseLayerVersionArn(arn);
                    var getLayerResponse = await lambdaClient.GetLayerVersionAsync(new GetLayerVersionRequest { LayerName = p.Name, VersionNumber = p.VersionNumber });

                    LayerDescriptionManifest manifest;
                    if (!LambdaUtilities.AttemptToParseLayerDescriptionManifest(getLayerResponse.Description, out manifest))
                    {
                        logger.WriteLine($"... {arn}: Skipped, does not contain a layer description manifest");
                        continue;
                    }
                    if (manifest.Nlt != LayerDescriptionManifest.ManifestType.RuntimePackageStore)
                    {
                        logger.WriteLine($"... {arn}: Skipped, layer is of type {manifest.Nlt.ToString()}, not {LayerDescriptionManifest.ManifestType.RuntimePackageStore}");
                        continue;
                    }

                    string filePath = Path.GetTempFileName();
                    using (var getResponse = await s3Client.GetObjectAsync(manifest.Buc, manifest.Key))
                        using (var reader = new StreamReader(getResponse.ResponseStream))
                        {
                            await getResponse.WriteResponseStreamToFileAsync(filePath, false, default(System.Threading.CancellationToken));
                        }

                    logger.WriteLine($"... {arn}: Downloaded package manifest for runtime package store layer");
                    info.Items.Add(new LayerPackageInfo.LayerPackageInfoItem
                    {
                        Directory    = manifest.Dir,
                        ManifestPath = filePath
                    });
                }
                catch (Exception e)
                {
                    logger.WriteLine($"... {arn}: Skipped, error inspecting layer. {e.Message}");
                }
            }

            return(info);
        }
        /// <summary>
        /// Execute the dotnet publish command and zip up the resulting publish folder.
        /// </summary>
        /// <param name="defaults"></param>
        /// <param name="logger"></param>
        /// <param name="workingDirectory"></param>
        /// <param name="projectLocation"></param>
        /// <param name="targetFramework"></param>
        /// <param name="configuration"></param>
        /// <param name="msbuildParameters"></param>
        /// <param name="disableVersionCheck"></param>
        /// <param name="publishLocation"></param>
        /// <param name="zipArchivePath"></param>
        public static bool CreateApplicationBundle(LambdaToolsDefaults defaults, IToolLogger logger, string workingDirectory,
                                                   string projectLocation, string configuration, string targetFramework, string msbuildParameters,
                                                   bool disableVersionCheck, LayerPackageInfo layerPackageInfo,
                                                   out string publishLocation, ref string zipArchivePath)
        {
            LogDeprecationMessagesIfNecessary(logger, targetFramework);

            if (string.IsNullOrEmpty(configuration))
            {
                configuration = LambdaConstants.DEFAULT_BUILD_CONFIGURATION;
            }

            var computedProjectLocation = Utilities.DetermineProjectLocation(workingDirectory, projectLocation);

            var lambdaRuntimePackageStoreManifestContent = LambdaUtilities.LoadPackageStoreManifest(logger, targetFramework);

            var publishManifestPath = new List <string>();

            if (!string.IsNullOrEmpty(lambdaRuntimePackageStoreManifestContent))
            {
                var tempFile = Path.GetTempFileName();
                File.WriteAllText(tempFile, lambdaRuntimePackageStoreManifestContent);
                publishManifestPath.Add(tempFile);
            }

            if (layerPackageInfo != null)
            {
                foreach (var info in layerPackageInfo.Items)
                {
                    publishManifestPath.Add(info.ManifestPath);
                }
            }

            var cli = new LambdaDotNetCLIWrapper(logger, workingDirectory);

            publishLocation = Utilities.DeterminePublishLocation(workingDirectory, projectLocation, configuration, targetFramework);
            logger?.WriteLine("Executing publish command");
            if (cli.Publish(defaults, projectLocation, publishLocation, targetFramework, configuration, msbuildParameters, publishManifestPath) != 0)
            {
                return(false);
            }

            var buildLocation = Utilities.DetermineBuildLocation(workingDirectory, projectLocation, configuration, targetFramework);

            // This is here for legacy reasons. Some older versions of the dotnet CLI were not
            // copying the deps.json file into the publish folder.
            foreach (var file in Directory.GetFiles(buildLocation, "*.deps.json", SearchOption.TopDirectoryOnly))
            {
                var destinationPath = Path.Combine(publishLocation, Path.GetFileName(file));
                if (!File.Exists(destinationPath))
                {
                    File.Copy(file, destinationPath);
                }
            }

            bool flattenRuntime     = false;
            var  depsJsonTargetNode = GetDepsJsonTargetNode(logger, publishLocation);

            // If there is no target node then this means the tool is being used on a future version of .NET Core
            // then was available when the this tool was written. Go ahead and continue the deployment with warnings so the
            // user can see if the future version will work.
            if (depsJsonTargetNode != null && string.Equals(targetFramework, "netcoreapp1.0", StringComparison.OrdinalIgnoreCase))
            {
                // Make sure the project is not pulling in dependencies requiring a later version of .NET Core then the declared target framework
                if (!ValidateDependencies(logger, targetFramework, depsJsonTargetNode, disableVersionCheck))
                {
                    return(false);
                }

                // Flatten the runtime folder which reduces the package size by not including native dependencies
                // for other platforms.
                flattenRuntime = FlattenRuntimeFolder(logger, publishLocation, depsJsonTargetNode);
            }

            if (zipArchivePath == null)
            {
                zipArchivePath = Path.Combine(Directory.GetParent(publishLocation).FullName, new DirectoryInfo(computedProjectLocation).Name + ".zip");
            }

            zipArchivePath = Path.GetFullPath(zipArchivePath);
            logger?.WriteLine($"Zipping publish folder {publishLocation} to {zipArchivePath}");
            if (File.Exists(zipArchivePath))
            {
                File.Delete(zipArchivePath);
            }

            var zipArchiveParentDirectory = Path.GetDirectoryName(zipArchivePath);

            if (!Directory.Exists(zipArchiveParentDirectory))
            {
                logger?.WriteLine($"Creating directory {zipArchiveParentDirectory}");
                new DirectoryInfo(zipArchiveParentDirectory).Create();
            }


            BundleDirectory(zipArchivePath, publishLocation, flattenRuntime, logger);

            return(true);
        }