private async Task DeployCloudServiceAsync(
            ComputeManagementClient computeClient,
            CloudBlobContainer container,
            string serviceName,
            string packagePath,
            string configurationPath,
            string diagnosticsConfigurationPath,
            DeploymentSlot targetSlot)
        {
            ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                     $"[{serviceName}] Checking the existence of an existing deployment"));

            var deployment = await computeClient.GetAzureDeyploymentAsync(serviceName, targetSlot);

            if (ForceDelete && deployment != null)
            {
                ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                         $"[{serviceName}] ForceDelete is true and found an existing deployment: Deleting it."));

                await computeClient.Deployments.DeleteBySlotAsync(serviceName, targetSlot);

                deployment = null;
            }

            var blob = container.GetBlockBlobReference(DateTime.Now.ToString("yyyyMMdd_HHmmss_") + Path.GetFileName(packagePath));

            ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                     $"[{serviceName}] Uploading the cloud service package to storage account {StorageAccountName} in the {StorageContainer} container."));

            await blob.UploadFromFileAsync(packagePath, FileMode.Open);

            if (diagnosticsConfigurationPath != null)
            {
                ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                         $"[{serviceName}] Checking the Cloud Service for the PaaS Diagnostics extension -> Creating it if it doesn't exist."));

                var diagnosticsConfiguration = File.ReadAllText(diagnosticsConfigurationPath);
                var diagnosticsCreated       = await computeClient.AddDiagnosticsExtensionIfNotExistsAsync(serviceName, diagnosticsConfiguration);

                if (!diagnosticsCreated)
                {
                    diagnosticsConfigurationPath = null;
                }
            }

            if (deployment == null)
            {
                ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                         $"[{serviceName}] Found no previous deployments -> Creating a new deployment into {targetSlot.GetEnumDescription()}."));

                var createParams = new DeploymentCreateParameters
                {
                    Label           = serviceName,
                    Name            = $"{serviceName}{targetSlot.GetEnumDescription()}",
                    PackageUri      = blob.Uri,
                    Configuration   = File.ReadAllText(configurationPath),
                    StartDeployment = true
                };

                if (diagnosticsConfigurationPath != null)
                {
                    createParams.ExtensionConfiguration = new ExtensionConfiguration {
                        AllRoles = new[] { new ExtensionConfiguration.Extension {
                                               Id = FlexConfiguration.FlexDiagnosticsExtensionId
                                           } }
                    };
                }

                await computeClient.Deployments.CreateAsync(serviceName, targetSlot, createParams);
            }
            else
            {
                ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                         $"[{serviceName}] Found a previous deployment -> Updating the current deployment in {targetSlot.GetEnumDescription()}."));

                await computeClient.Deployments.UpgradeBySlotAsync(
                    serviceName,
                    targetSlot,
                    new DeploymentUpgradeParameters
                {
                    Label         = serviceName,
                    PackageUri    = blob.Uri,
                    Configuration = File.ReadAllText(configurationPath)
                });
            }

            if (VipSwap)
            {
                ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                         $"[{serviceName}] Swapping the deployments."));

                await computeClient.Deployments.SwapAsync(
                    serviceName,
                    new DeploymentSwapParameters
                {
                    SourceDeployment = $"{serviceName}{targetSlot.GetEnumDescription()}"
                });

                if (DeleteStaging)
                {
                    ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                             $"[{serviceName}] Deleting the staging deployment after the swap."));

                    await computeClient.Deployments.DeleteBySlotAsync(serviceName, DeploymentSlot.Staging);
                }
            }

            ThreadAdapter.QueueObject(new BuildEvent(BuildEventType.Information, BuildEventImportance.Medium,
                                                     $"[{serviceName}] Deployment complete."));
        }