gpt4 book ai didi

azure - 如何使用 dotnet SDK 删除 Azure 中的单个资源?

转载 作者:行者123 更新时间:2023-12-03 04:18:14 29 4
gpt4 key购买 nike

我一直在尝试使用DeleteById,但是从我看到的所有示例来看,您似乎需要知道要删除什么类型的资源才能使用此方法。

这就是我一直尝试调用它的方式,但收到错误“IResourcesOperations”不包含“DeleteById”的定义,并且最佳扩展方法重载“PolicyAssignmentsOperationsExtensions.DeleteById(IPolicyAssignmentsOperations, string)”需要接收器类型为“IPolicyAssignmentsOperations”。

var resourceManagementClient = new 
ResourceManagementClient(TokenCredentials){
SubscriptionId = AzureSubscriptionId
};

resourceManagementClient.Resources.DeleteById("idhere");

尝试使用删除方法时,我遇到了同样的错误。

有没有办法在不知道资源是什么类型的情况下删除单个资源?例如,您可以通过知道 id 和资源组或类似的信息来删除资源吗?

最佳答案

can you delete a resource by knowing the id and the resource group or something similar?

是的,我们可以删除具有已知 ID 的单个资源。

请尝试使用以下代码。

resourceManagementClient.Resources.DeleteById("resourceId", "Apiversion");

以WebApp为例-resourceId格式:

/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{name}

API版本:2018-02-01

我们可以从 delete resource API 获取 Api 版本

DELETE https://management.azure.com/{resourceId}?api-version=2018-02-01

包.config

<packages>
<package id="Microsoft.Azure.Management.ResourceManager" version="1.9.0-preview" targetFramework="net471" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.11" targetFramework="net471" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.12" targetFramework="net471" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net471" />
</packages>

关于azure - 如何使用 dotnet SDK 删除 Azure 中的单个资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51217050/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com