gpt4 book ai didi

在 Azure .Net SDK 中找不到 AzureCredentials

转载 作者:行者123 更新时间:2023-12-03 05:54:13 24 4
gpt4 key购买 nike

我一定错过了一些愚蠢的事情。我正在尝试对我的服务器备份应用程序进行身份验证,以访问我的 Azure 帐户,以便我可以执行诸如以编程方式创建存储帐户等操作。如果我理解正确,您必须创建一个服务主体。我想我已经解决了这个问题,现在我只需要添加代码:

  AzureCredentials credentials = AzureCredentials.FromServicePrincipal(client, key, tenant, AzureEnvironment.AZURE);
Azure azure = Azure.authenticate(credentials).withSubscription(subscriptionId);

问题是找不到“AzureCredentials”和“Azure”或“IAzure”的引用。我已经安装了Azure SDK,添加了如下引用:

using Microsoft.WindowsAzure;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Management;
using Microsoft.WindowsAzure.ActiveDirectory.Authentication;

...没什么!我错过了什么?

编辑:下面答案中建议的包是正确的,但仍然找不到“Azure”引用。我相信它在“Microsoft.Azure.Management.Fluent”中,但是当我尝试添加它时,我得到了这个:

Failed to add reference. The package 'Microsoft.Azure.Management.AppService.Fluent' tried to add a framework reference to 'System.Xml.XDocument' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance. 0

最佳答案

您应该使用Microsoft.Azure.Management.ResourceManager.Fluent sdk并引用document ,您可以尝试以下代码使用 ServicePrincipal 登录:

AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(...) 

或者

var credentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = "xxxxxx", ClientSecret = "xxxxx" }, "tenantid", AzureEnvironment.AzureGlobalCloud); 

关于在 Azure .Net SDK 中找不到 AzureCredentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43991093/

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