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

时间:2016-02-12 03:38:49

标签: c# azure resources azure-resource-manager azure-sdk-.net

我使用类似于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 个答案:

答案 0 :(得分: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);

注意:此代码示例应向后兼容上述nuget包的旧版本。

希望这有帮助!

相关问题