Azure.Fluent.Management 和 Azure.Storage.Blobs 包之间有冲突吗?

conflict between Azure.Fluent.Management and Azure.Storage.Blobs packages?

在我的项目中,我安装了 Microsoft.Azure.Management.Fluent 包(版本 1.27)来为我的 Azure 订阅进行资源管理。我的连接对象如下所示:

AzureCredentials credentials = GenerateCredentials(); // custom method that returns my creds.
IAzure azureConn = Azure
   .Configure()
   .Authenticate(credentials)
   .WithDefaultSubscription();

这很好用。今天,我安装了 Azure.Storage.BlobsNuget (版本 12.4)。安装这个包后,我得到一个错误:

> CS0234 C# The type or namespace name 'Configure' does not exist in the
> namespace 'Azure' (are you missing an assembly reference?)

当我卸载 Azure.Storage.Blobs 软件包时,错误消失了。这里可能发生了什么?我在 Net Core 2.2 MVC 项目中使用它。

您应该使用完全限定的 class 名称而不是 Azure class 来解决冲突,下面的代码是可以的:

IAzure azureConn = Microsoft.Azure.Management.Fluent.Azure
                  .Configure()
                  .Authenticate(credentials)
                  .WithDefaultSubscription();

原因是安装 Azure.Storage.Blobs 后,有一个命名空间 Azure 包含用于 blob 存储。所以在代码中,当你输入Azure.Configure()时,编译器会混淆,Azurenamespace还是class?显然,它会将 Azure 视为命名空间(这里,Azure 命名空间用于存储 blob),但 Configure() 方法不在此命名空间中,则会抛出此类错误。