使用 Azure SDK 将多个地址前缀添加到网络子网

Adding multiple address prefixes to network subnet using Azure SDK

我有带子网的现有网络,其中指定了 IPV4 地址前缀。 在 C# 中使用 Azure SDK 我需要添加额外的 IPV6 地址前缀而不删除现有地址前缀。 我设法在门户网站中使用 Microsoft REST API 做到了这一点,但我的目标是使用他们的 SDK 来实现它。这是我到目前为止写的代码:

await networkToUpdate.Update()
                        .UpdateSubnet(network.SubnetAzureId)
                        .WithAddressPrefix("10.0.0.0/21")
                        .WithAddressPrefix("ace:cab:dca:deed::/64")
                        .Parent()
                        .ApplyAsync();

不幸的是,它只允许设置一个地址前缀,在这种情况下就是IPV6。 有什么方法可以通过SDK添加两个地址前缀吗?

请使用以下代码:

        var clientId = "xxx";
        var clientSecret = "xxx";
        var tenantId = "xxx";

        var creds = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);

        var azure = Azure.Configure()
            .Authenticate(creds)                
            .WithDefaultSubscription();

        var myvnet = azure.Networks.GetById("/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworks/xxx");
       

        //use the code below to update multi address prefixes
        IList<string> list = new List<string>() { "172.18.3.0/24", "ace:cab:dca:deed::/64" };
        myvnet.Subnets["the_subnet_name"].Inner.AddressPrefix = "";
        myvnet.Subnets["the_subnet_name"].Inner.AddressPrefixes = list;

        myvnet.Update().Apply();  

测试结果:

如果您对此仍有疑问,请告诉我。