Microsoft.Web.Deployment:如何在同步新版本之前使目标脱机?

时间:2017-02-14 14:51:42

标签: c# azure azure-web-sites web-deployment msdeploy

我的Microsoft.Web.Deployment包有问题。有人在这里可以告诉我,在使用新版本更新之前,我必须如何编写/配置同步过程,目标将被关闭?

这是我的片段:

var publishSettings = GetPublishSettings(subscriptionId, resourcegroupName, websiteName);
var sourceBaseOptions = new DeploymentBaseOptions();

var targetBaseOptions = new DeploymentBaseOptions
{
    ComputerName = publishSettings.ComputerName,
    UserName = publishSettings.Username,
    Password = publishSettings.Password,
    AuthenticationType = "basic",
    TraceLevel = Verbose
 };
 targetBaseOptions.Trace += TargetBaseOptions_Trace;
 var syncOptions = new DeploymentSyncOptions
 {
     DoNotDelete = false,
     WhatIf = false,
     UseChecksum = true
 };

 using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, Path.GetFullPath(websitePath), sourceBaseOptions))
 {
       var summary = deploymentObject.SyncTo(DeploymentWellKnownProvider.ContentPath, publishSettings.SiteName, targetBaseOptions, syncOptions);
       if (summary.Errors > 0) throw new Exception("Website Deployment failed");
       if (summary.Errors == 0)
       {
           Console.WriteLine($"{publishSettings.SiteName}: erfolgreich");
       }
 }

我可以想象它是DeploymentSyncOptions

中的东西 谢谢你们

1 个答案:

答案 0 :(得分:1)

Microsoft.Web.Deployment,我找不到提供管理(停止,重启等)Azure网站的方法或选项。如果您想在部署之前停止Azure网站,可以尝试使用为Microsoft Azure提供网站管理功能的Microsoft.Azure.Management.WebSites

WebSiteManagementClient websiteManagementClient = new WebSiteManagementClient(cred);

websiteManagementClient.SubscriptionId = "your subscription id here";
websiteManagementClient.Sites.StopSite(AzureResourceGroup, siteName);

您可以使用websiteManagementClient.Sites.GetSite(AzureResourceGroup, siteName).State来检查网站状态。

enter image description here