繁体   English   中英

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

[英]Cannot find namespace Microsoft.Azure in Visual Studio Mac

我正在尝试创建一个简单的DocumentDb hello世界程序,并type or namespace name 'Azure' does not exist in namespace 'Microsoft'获取type or namespace name 'Azure' does not exist in namespace 'Microsoft'

using Microsoft.Azure

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

根据另一个SO线程 ,看来您使用的是.net项目而不是.net核心项目。

.NET Framework提供了用于在Windows上构建从移动设备到Web到桌面的各种应用程序的全面编程模型。

请尝试创建一个.net核心项目。 我们可以从nuget获取Microsoft.Azure.DocumentDB.Core 我测试了在带有.net核心项目的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; }
    }

在此处输入图片说明

我们还可以从获得更多的文件示例代码文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM