![](/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.