如何用 Microsoft.Azure.Storage.Blob 替换 Microsoft.WindowsAzure.Storage

How to replace Microsoft.WindowsAzure.Storage with Microsoft.Azure.Storage.Blob

在我的 asp.net mvc 应用程序中,我将 Microsoft.WindowsAzure.Storage 8.0.1 用于 uploading/downloading blob to/from Azure 云容器。现在 NuGet 包管理器通知我 Microsoft.WindowsAzure.Storage 已弃用,我应该使用 Microsoft.Azure.Storage.Blob.

问题:

  1. 如果我继续使用 Microsoft.WindowsAzure.Storage 8.0.1,我 运行 会遇到什么问题?
  2. 是否有任何推荐的方法可以将 Microsoft.WindowsAzure.Storage 8.0.1 替换为 Microsoft.Azure.Storage.Blob?
  3. 当我用 Microsoft.Azure.Storage.Blob 替换 Microsoft.WindowsAzure.Storage 8.0.1 时,我是否必须重新编写处理 uploading/downloading blob 的代码?

如有任何帮助和建议,我们将不胜感激。

首先,稍微更正一下。 Microsoft.Azure.Storage.Blob has been replaced by a newer SDK Azure.Storage.Blobs and it is recommended you upgrade to the new one (v12 SDSK) instead. It was a move by Microsoft to update all their SDKs to follow unified API standard. You can read more about that here

Into what problems could I run, when I keep on using Microsoft.WindowsAzure.Storage 8.0.1?

WindowsAzure.Storage 已弃用,最后一个版本 9.3.3 于 2018 年 11 月发布。虽然它仍然有效并且尚未失去支持,但建议移动到更新的 Azure.Storage.Blobs包以在未来利用更好的性能、更新、功能发布和持续支持。

Are there any recommended ways to replace Microsoft.WindowsAzure.Storage 8.0.1 with Microsoft.Azure.Storage.Blob?

如开头所述,正确的包是 Azure.Storage.Blobs actually. There is a good article on the update guide and tips here

When I replace Microsoft.WindowsAzure.Storage 8.0.1 with Microsoft.Azure.Storage.Blob, will I have to re-write my code for dealing with uploading/downloading blob?

升级到旧包 Microsoft.Azure.Storage.Blob will need very little change in code. But the latest SDK Azure.Storage.Blobs will need you some changes. As described here,命名空间、类、方法有几处更改。

|  Package  |    Old Microsoft.Azure.Storage.Blob   |   v12   Azure.Storage.Blobs   |
|:---------:|:-------------------------------------:|:-----------------------------:|
| Namespace | Microsoft.Azure.Storage.Blob.Protocol | Azure.Storage.Blobs.Models    |
| Namespace | Microsoft.Azure.Storage.Blob          | Azure.Storage.Blobs           |
| Namespace | Microsoft.Azure.Storage               | Azure                         |
| Class     | CloudBlobClient                       | BlobServiceClient             |
| Class     | CloudBlobContainer                    | BlobContainerClient           |
| Class     | CloudBlockBlob                        | BlobClient or BlockBlobClient |
| Class     | StorageException                      | RequestFailedException        |
| Class     | BlobErrorCodeStrings                  | BlobErrorCode                 |

更新:由于您使用的是 .net framework 4.5.2,Azure.Storage.Blobs is not supported for you. You would have to go with Microsoft.Azure.Storage.Blob.