我们做了一个非常相似的过程,对大约 50 多个站点使用相同的代码库。我们使用Azure REST 管理 API来完成部署。我建议将站点特定设置从 web.config 移动到单个 ServiceConfiguration..cscfg 文件,然后CloudConfigurationManager.GetSetting("settingsKey")
用于获取配置值。创建一个简单的密钥列表,可能基于域以访问您的设置。
Azure 团队在此处提供了一个关于使用管理 API的出色代码示例。我们针对我们的代码库进行了调整,以创建一个控制台应用程序并在 TFS 构建过程中调用该控制台应用程序。下面是我们用来获取订阅中托管服务列表然后更新每个托管服务部署的相关代码:
var packageUrl = UploadFileToBlob(package);
var services = new ListHostedServicesCommand();
services.Run();
hostedServices = services.HostedServices;
var date = DateTime.UtcNow.ToString("yyyyMMdd-hhmmss-");
var label = date + "some-deployment-name";
var fileinfo = new FileInfo(config);
if (!string.IsNullOrEmpty(packageUrl) && fileinfo.Exists)
{
// get the url of the package uploaded to blob
AzureCommand.PackageLocation = packageUrl;
AzureCommand.ConfigFileLocation = fileinfo.FullName;
AzureCommand.DeploymentSlot = "production";
AzureCommand.Mode = "auto";
AzureCommand.Label = label;
foreach (var hostedService in hostedServices)
{
Console.WriteLine("updating: " + hostedService.ServiceName);
// get the deployment unique name - required for upgrade
AzureCommand.HostedServiceName = hostedService.ServiceName;
AzureCommand.DeploymentName = null;
var getDeployment = new GetDeploymentCommand();
getDeployment.Run();
AzureCommand.DeploymentName = getDeployment.Deployment.Name;
// upgrade the existing deployment
var upgradeDeployment = new UpgradeDeploymentCommand();
upgradeDeployment.Run();
servicesOperations.Add(upgradeDeployment.TrackingId, upgradeDeployment.ServiceManagement);
}
// check status of all operations submitted
foreach (var servicesOperation in servicesOperations)
{
// check status of operations
AzureCommand.WaitForAsyncOperation(servicesOperation.Value, servicesOperation.Key);
}
}