public void SetupWindowsDeploymentManifest()

in src/AWS.Deploy.Orchestration/ServiceHandlers/AWSElasticBeanstalkHandler.cs [117:213]


        public void SetupWindowsDeploymentManifest(Recommendation recommendation, string dotnetZipFilePath)
        {
            var iisWebSiteOptionSetting = _optionSettingHandler.GetOptionSetting(recommendation, Constants.ElasticBeanstalk.IISWebSiteOptionId);
            var iisAppPathOptionSetting = _optionSettingHandler.GetOptionSetting(recommendation, Constants.ElasticBeanstalk.IISAppPathOptionId);

            var iisWebSiteValue = _optionSettingHandler.GetOptionSettingValue<string>(recommendation, iisWebSiteOptionSetting);
            var iisAppPathValue = _optionSettingHandler.GetOptionSettingValue<string>(recommendation, iisAppPathOptionSetting);

            var iisWebSite = !string.IsNullOrEmpty(iisWebSiteValue) ? iisWebSiteValue : "Default Web Site";
            var iisAppPath = !string.IsNullOrEmpty(iisAppPathValue) ? iisAppPathValue : "/";

            var newManifestFile = new ElasticBeanstalkWindowsManifest();
            newManifestFile.Deployments.AspNetCoreWeb.Add(new ElasticBeanstalkWindowsManifest.ManifestDeployments.AspNetCoreWebDeployments
            {
                Parameters = new ElasticBeanstalkWindowsManifest.ManifestDeployments.AspNetCoreWebDeployments.AspNetCoreWebParameters
                {
                    IISPath = iisAppPath,
                    IISWebSite = iisWebSite
                }
            });

            using (var zipArchive = ZipFile.Open(dotnetZipFilePath, ZipArchiveMode.Update))
            {
                var zipEntry = zipArchive.GetEntry(Constants.ElasticBeanstalk.WindowsManifestName);
                var serializedManifest = JsonSerializer.Serialize(new Dictionary<string, object>());
                if (zipEntry != null)
                {
                    using (var streamReader = new StreamReader(zipEntry.Open()))
                    {
                        serializedManifest = streamReader.ReadToEnd();
                    }
                }

                var jsonDoc = GetOrCreateNode<Dictionary<string, object>>(serializedManifest);

                if (!jsonDoc.ContainsKey("manifestVersion"))
                {
                    jsonDoc["manifestVersion"] = newManifestFile.ManifestVersion;
                }

                if (jsonDoc.ContainsKey("deployments"))
                {
                    var deploymentNode = GetOrCreateNode<Dictionary<string, object>>(jsonDoc["deployments"]);

                    if (deploymentNode.ContainsKey("aspNetCoreWeb"))
                    {
                        var aspNetCoreWebNode = GetOrCreateNode<List<object>>(deploymentNode["aspNetCoreWeb"]);
                        if (aspNetCoreWebNode.Count == 0)
                        {
                            aspNetCoreWebNode.Add(newManifestFile.Deployments.AspNetCoreWeb[0]);
                        }
                        else
                        {
                            // We only need 1 entry in the 'aspNetCoreWeb' node that defines the parameters we are interested in. Typically, only 1 entry exists.
                            var aspNetCoreWebEntry = GetOrCreateNode<Dictionary<string, object>>(JsonSerializer.Serialize(aspNetCoreWebNode[0]));

                            var nameValue = aspNetCoreWebEntry.ContainsKey("name") ? aspNetCoreWebEntry["name"].ToString() : string.Empty;
                            aspNetCoreWebEntry["name"] = !string.IsNullOrEmpty(nameValue) ? nameValue : newManifestFile.Deployments.AspNetCoreWeb[0].Name;

                            if (aspNetCoreWebEntry.ContainsKey("parameters"))
                            {
                                var parametersNode = GetOrCreateNode<Dictionary<string, object>>(aspNetCoreWebEntry["parameters"]);
                                parametersNode["appBundle"] = ".";
                                parametersNode["iisPath"] = iisAppPath;
                                parametersNode["iisWebSite"] = iisWebSite;

                                aspNetCoreWebEntry["parameters"] = parametersNode;
                            }
                            else
                            {
                                aspNetCoreWebEntry["parameters"] = newManifestFile.Deployments.AspNetCoreWeb[0].Parameters;
                            }
                            aspNetCoreWebNode[0] = aspNetCoreWebEntry;
                        }
                        deploymentNode["aspNetCoreWeb"] = aspNetCoreWebNode;
                    }
                    else
                    {
                        deploymentNode["aspNetCoreWeb"] = newManifestFile.Deployments.AspNetCoreWeb;
                    }

                    jsonDoc["deployments"] = deploymentNode;
                }
                else
                {
                    jsonDoc["deployments"] = newManifestFile.Deployments;
                }

                using (var jsonStream = new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(jsonDoc, new JsonSerializerOptions { WriteIndented = true })))
                {
                    zipEntry ??= zipArchive.CreateEntry(Constants.ElasticBeanstalk.WindowsManifestName);
                    using var zipEntryStream = zipEntry.Open();
                    jsonStream.Position = 0;
                    jsonStream.CopyTo(zipEntryStream);
                }
            }
        }