如何在 .NET Core 2.2 应用程序中创建 CloudTableClient?

How can I create a CloudTableClient in .NET Core 2.2 app?

这对于 .NET Core 2 来说已经是一团糟了!

我需要一个非常简单的东西 - 我需要在我的 .NET Core 2.2 应用程序中使用 Table 存储,使用 Microsoft.Azure.CosmosDB.Table 包。好的,让我们开始吧?

首先,让我们创建 CloudTableClient:

using Microsoft.Azure.CosmosDB.Table;
using Microsoft.Azure.Storage.Common;

…

CloudTableClient tableClient = new CloudTableClient(
  new Uri("[WHAT TO PUT IN HERE in case of Azure and Emulator???]"),
  new Microsoft.Azure.Storage.Auth.StorageCredentials() // => **THIS DOES NOT EVEN COMPILE! Auth is not a part of the package **
);

不错!我们从这里去哪里? 请不要向我指出示例 - 它们不适用于 .NET Core 2.2!

我们不要混用 Microsoft.Azure.StorageMicrosoft.WindowsAzure.Storage 包!

什么时候修复这个问题?如何创建 CloudTableClient 并使用 CloudTable?

我不得不得出结论,无法在 .NET Core 2.x 项目中使用 Azure 表。不能降级到某些旧软件包或预览版本。

这很好用:

var tableName = "TestTempTable";
var storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=....;AccountKey=....;EndpointSuffix=core.windows.net";
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
var tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());
var table = tableClient.GetTableReference(tableName);
await table.CreateIfNotExistsAsync();