3

我正在尝试使用 nuget 包创建一个新网站Microsoft.WindowsAzure.Management.WebSites (Version 3.0.0)

本教程很有帮助(即使它是 Java): http ://azure.microsoft.com/fi-fi/documentation/articles/java-create-azure-website-using-java-sdk/ 除了它建议使用WebSpaceNames.WestUSWebSpace持续的。

var hostingPlanParams = new WebHostingPlanCreateParameters
{
    Name = this.webhostingPlanName,
    NumberOfWorkers = 1,
    SKU = SkuOptions.Free,
    WorkerSize = WorkerSizeOptions.Small
};
var result = new WebSiteManagementClient(this.Credentials)
    .WebHostingPlans
    .CreateAsync(WebSpaceNames.WestUSWebSpace, hostingPlanParams, CancellationToken.None)
    .Result

这将导致异常:NotFound: Cannot find WebSpace with name westuswebspace.

我实际上想创建一个自定义 WebSpace。

除了我找不到任何方法。见 MSDN

因此,我能够完成这项工作的唯一方法是使用通过该manage.windowsazure.com站点创建的现有 WebSpace。这违背了自动化的整个目的。

唯一的 Create[...] 方法IWebSpaceOperationsCreatePublishingUserAsync我也尝试过运行它,但它会导致异常This operation is not supported for subscriptions that have co-admins.这本身很烦人,对我来说没有多大意义,但并不是我问题的核心.

4

1 回答 1

0

我通过使用预发布包解决了这个问题:PM> Install-Package Microsoft.Azure.Management.WebSites -Pre 效果很好。除了它只是原因的预发布

// Create Web Hosting Plan
var hostingPlanParams = new WebHostingPlanCreateOrUpdateParameters
{
    WebHostingPlan = new WebHostingPlan()
    {
        Name = "WebHostingPlanName",
        Location = "Australia Southeast",
        Properties = new WebHostingPlanProperties
        {
            NumberOfWorkers = 1,
            Sku = SkuOptions.Standard,
            WorkerSize = WorkerSizeOptions.Small
        }
    },
};
var result = this.ManagementContext.WebSiteManagementClient.WebHostingPlans.CreateOrUpdateAsync(
        "ResourceGroupName",
        "WebHostingPlanName",
        CancellationToken.None).Result;

// Create Website
var websiteParams = new WebSiteCreateOrUpdateParameters
{
    WebSite = new WebSiteBase
    {
        Location = "Australia Southeast",
        Name = "WebSiteName",
        Properties = new WebSiteBaseProperties
        {
            ServerFarm = "WebHostingPlanName"
        }
    }
};

var siteResult = this.ManagementContext.WebSiteManagementClient.WebSites.CreateOrUpdateAsync(
        "ResourceGroupName",
        "WebSiteName",
        null,
        websiteParams,
        CancellationToken.None).Result;

如果你想使用部署槽,你必须考虑到这一点: https ://github.com/Azure/azure-sdk-for-net/issues/1088

于 2015-06-30T23:30:47.670 回答