Azure的资源组设置标签与SDK? [英] Azure Resource Group Set Tags with SDK?

查看:232
本文介绍了Azure的资源组设置标签与SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用类似code到<一个href=\"http://blogs.infinitesquare.com/b/tranise/archives/-azure-resource-group-une-nouvelle-facon-dorganiser-ses-environnements-dans-azure#.Vr1RrfIrLgk\" rel=\"nofollow\">http://blogs.infinitesquare.com/b/tranise/archives/-azure-resource-group-une-nouvelle-facon-dorganiser-ses-environnements-dans-azure#.Vr1RrfIrLgk在Azure中创建资源组与C#。我现在想通过把标签上的资源来扩展它。

I have used code similar to http://blogs.infinitesquare.com/b/tranise/archives/-azure-resource-group-une-nouvelle-facon-dorganiser-ses-environnements-dans-azure#.Vr1RrfIrLgk to create a Resource Group in Azure with C#. I am now trying to extend it by putting Tags on the Resource.

添加 resourceGroupGetResult.ResourceGroup.Tags.Add(A,1)工作,但随后CreateOrUpdateAsync调用失败

Adding resourceGroupGetResult.ResourceGroup.Tags.Add("a","1") works, but a subsequent CreateOrUpdateAsync call fails with

"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.'."

什么是标签添加到资源组的正确方法是什么?当然,我希望在这之后,以同样的标签添加到组内的资源。

What is the correct way to add Tags to a Resource Group? Of course I will want to add the same Tags to resources within the Group after this.

感谢。

推荐答案

我假设你正在使用的NuGet包ID = Microsoft.Azure.Management.Resources 版本= 3.4 .0- preVIEW

I assume you're using nuget package id="Microsoft.Azure.Management.Resources" version="3.4.0-preview".

样品code使用上述ARM .NET SDK添加标签(县)的Azure资源集团是如下:

The sample code for adding tag(s) to Azure Resource Group using the ARM .NET SDK above is as below:

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

注意:这code样品应与上述的NuGet包的旧版本版本的向后兼容。

Note: This code sample should backward-compatible with older release version of the above-mentioned nuget package.

希望这有助于!

这篇关于Azure的资源组设置标签与SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆