c# - 在 Visual Studio Mac 中找不到命名空间 Microsoft.Azure

标签 c# .net azure xamarin-studio visual-studio-mac

我正在尝试创建一个简单的 DocumentDb hello world 程序,但收到命名空间“Microsoft”中不存在类型或命名空间名称“Azure”

使用 Microsoft.Azure

我通过 Nuget 添加了 DocumentDb 库。添加nuget包后是否需要手动添加对其的引用?我认为使用 nuget 会自动添加项目引用。

最佳答案

根据你的另一个SO thread ,看来您使用了 .net project不是.net core项目。

The .NET Framework provides a comprehensive programming model for building all kinds of applications on Windows, from mobile to web to desktop.

请尝试创建一个.net core项目。 我们可以得到Microsoft.Azure.DocumentDB.Core来自努盖特。我测试使用 .net core 项目在 Windows 平台上创建文档。它在我这边工作正常。我认为它也应该适用于 Mac。以下是我的演示代码。

 var endpointUrl = "https://documentdbnamespace.documents.azure.com:443/";
 var authorizationKey = "xxxxxxxxxx";
 var databaseId = "database";
 var collectionId = "collection"; //I use an existing collect


 using (_client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
    {
       var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
       var product = new Product
          {
             Id= Guid.NewGuid().ToString(),
             ProductId = "test"
          };
       Document created =  _client.CreateDocumentAsync(collectionLink, product).Result;
     }

Product.cs 类:

 public class Product
    {
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }

        // used to set expiration policy
        [JsonProperty(PropertyName = "ttl", NullValueHandling = NullValueHandling.Ignore)]
        public int? TimeToLive { get; set; }

        public string ProductId { get; set; }
        public DateTime DateStarted { get; set; }
    }

enter image description here

我们还可以从 document 获取更多文档示例代码.

关于c# - 在 Visual Studio Mac 中找不到命名空间 Microsoft.Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44328135/

相关文章:

c# - 可以单声道运行 framework.net 编译的应用程序(来自 VS 环境)

c# - 制作接收azure订阅数据的应用程序

c# - 在 CEFSharp 中处理 OnBeforePopUp 时如何设置新浏览器的框架名称

c# - 在 Habanero 中,我将如何限制从数据库返回的对象数量

C# 从详细信息 View 中的 ListView 中的第一项中获取文本

azure - CosmosDB 图 : Are per-request consistency levels supported the way they are for documents?

c# - 在Azure Function App中全局获取ExecutionContext

c# - 我可以在 C# 中创建经典的 VB 数组吗?

c# - 如何从子类向基类的字段添加属性?

.net - 我应该在 IIS 中托管我的 WCF 服务吗?