![](/img/trans.png)
[英]What package should I use for Azure Tables when migrating away from "WindowsAzure.Storage"
[英]Referencing services from CloudStorageAccount when migrating from WindowsAzure.Storage to Azure.Storage packages
我有一个代码库,它广泛使用WindowsAzure.Storage nuget package 来访问Queues, Tables 和 Blobs 。 package 现在被标记为已弃用,表明该功能已分解为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);
使用新包的等价物是什么?我需要什么样的包组合?
您将需要 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);
需要更改为:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.