首页 文章

Azure资源组使用SDK设置标签?

提问于
浏览
3

我使用类似于http://blogs.infinitesquare.com/b/tranise/archives/-azure-resource-group-une-nouvelle-facon-dorganiser-ses-environnements-dans-azure#.Vr1RrfIrLgk的代码在Azure中使用C#创建资源组 . 我现在试图通过在资源上放置标签来扩展它 .

添加 resourceGroupGetResult.ResourceGroup.Tags.Add("a","1") 有效,但后续的CreateOrUpdateAsync调用失败

"InvalidRequestContent: The request content was invalid and could not be deserialized: 'Could not find member 'provisioningState' on object of type 'ResourceGroupDefinition'. Path 'provisioningState', line 9, position 23.'."

将标记添加到资源组的正确方法是什么?当然,我希望在此之后将相同的标签添加到组内的资源 .

谢谢 .

1 回答

  • 3

    我假设你正在使用nuget package id =“ Microsoft.Azure.Management.Resources " version=" 3.4.0-preview ” .

    使用上面的ARM .NET SDK将标记添加到Azure资源组的示例代码如下:

    var tag = new Dictionary<string, string> {{tagName, tagValue}};
    var rg = new ResourceGroup() { Name = rgName, Location = rgLocation, Tags = tag };
    await client.ResourceGroups.CreateOrUpdateAsync(rgName, rg);
    

    Note :此代码示例应向后兼容上述nuget包的旧版本 .

    希望这可以帮助!

相关问题