我有一个代码库,它广泛使用WindowsAzure.Storage nuget 包来访问队列、表和 Blob。该包现在被标记为已弃用,并指示该功能已分解为Azure.Storage包集下的各个组件。
此 StackOverflow 问答提供了替换包的一些描述,但尚不清楚重组完成了多少,以及此时需要迁移哪些旧包和新包的组合。
我一直无法找到任何最新的迁移指南,并且新软件包的示例代码/文档往往侧重于基本操作。
具体来说,我很难从顶级存储帐户访问新服务。
当前的代码使用这样的模式......
var accountName = "...";
var accountKey ="..............";
var credentials = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(credentials,true);
//for table access...
var client = account.CreateCloudTableClient();
var table = client.GetTableReference(tableName);
//for queue access
var client = account.CreateCloudQueueClient();
var queue = client.GetQueueReference(queueName);
//for blob access
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(path);
Run Code Online (Sandbox Code Playgroud)
使用新软件包的等效内容是什么以及我需要什么软件包组合?
Gau*_*tri 11
您将需要 3 个独立的 Nuget 包:
Azure.Storage.Blobs:用于管理 blobAzure.Storage.Queues:用于管理队列和Microsoft.Azure.Cosmos.Table:用于管理表。就创建实例而言CloudStorageAccount,它在 Azure.Storage.Blobs 和 Azure.Storage.Queues 中不可用。你将不得不以不同的方式处理它。对于表,CloudStorageAccount 在 Microsoft.Azure.Cosmos.Table 命名空间中可用。
例如,旧SDK中的以下代码
var container = client.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(path);
Run Code Online (Sandbox Code Playgroud)
需要改成这样:
var blobContainerClient = new BlobContainerClient(connectionString, containerName);//Use this client to perform operations on blob container.
var blockBlobClient = blobContainerClient.GetBlockBlobClient(blobName);//Use this client to perform operations on block blob.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8156 次 |
| 最近记录: |