public void PublishService(string serviceRootPath)
        {
            AzureTool.Validate();
            WriteVerbose(string.Format(Resources.PublishServiceStartMessage, _hostedServiceName));

            // Package the service and all of its roles up in the open package format used by Azure
            if (InitializeSettingsAndCreatePackage(serviceRootPath))
            {
                if (ServiceExists())
                {
                    var deploymentStatusCommand = new GetDeploymentStatus(Channel, CommandRuntime)
                    { ShareChannel = ShareChannel, CurrentSubscription = CurrentSubscription };
                    bool deploymentExists = deploymentStatusCommand.DeploymentExists(
                        _azureService.Paths.RootPath,
                        _hostedServiceName,
                        _deploymentSettings.ServiceSettings.Slot,
                        _deploymentSettings.ServiceSettings.Subscription);
                    if (deploymentExists)
                    {
                        UpgradeDeployment();
                    }
                    else
                    {
                        CreateNewDeployment();
                    }
                }
                else
                {
                    CreateHostedService();
                    CreateNewDeployment();
                }

                // Verify the deployment succeeded by checking that each of the
                // roles are running
                VerifyDeployment();

                // After we've finished deploying, optionally launch a browser pointed at the service
                if (Launch && CanGenerateUrlForDeploymentSlot())
                {
                    LaunchService();
                }

                Deployment deployment = this.RetryCall<Deployment>(s => this.Channel.GetDeploymentBySlot(
                    s,
                    _hostedServiceName,
                    _deploymentSettings.ServiceSettings.Slot
                ));
                WriteObject(deployment);
            }
            else
            {
                WriteVerbose(Resources.PublishAbortedAtUserRequest);
            }

            WriteVerboseWithTimestamp(Resources.PublishCompleteMessage);
        }
        private void StopAndRemove(string rootName, string serviceName, string subscription, string slot)
        {
            var deploymentStatusCommand = new GetDeploymentStatus(Channel, CommandRuntime)
            { ShareChannel = ShareChannel, CurrentSubscription = CurrentSubscription };
            if (deploymentStatusCommand.DeploymentExists(rootName, serviceName, slot, subscription))
            {
                InvokeInOperationContext(() =>
                {
                    this.RetryCall(s => this.Channel.DeleteDeploymentBySlot(s, serviceName, slot));
                });

                // Wait until deployment is removed
                while (deploymentStatusCommand.DeploymentExists(rootName, serviceName, slot, subscription));
            }
        }