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

时间:2017-06-02 11:44:43

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

我正在尝试创建一个简单的DocumentDb hello world程序并且正在获取 Route::post('event/inviteforevent', ['as' => 'inviteforevent', uses' => 'UserController@invitebyemail']);

type or namespace name 'Azure' does not exist in namespace 'Microsoft'

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

1 个答案:

答案 0 :(得分:0)

根据您的另一个SO thread,您似乎使用了.net project而不是.net core项目。

  

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

请尝试创建一个.net核心项目。 我们可以从nuget获得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获得更多文档示例代码。