不能在Visual Studio中的Mac
问题描述:
找到命名空间Microsoft.Azure我尝试创建一个简单的DocumentDb Hello World程序,并正在逐渐type or namespace name 'Azure' does not exist in namespace 'Microsoft'
不能在Visual Studio中的Mac
using Microsoft.Azure
我通过的NuGet添加DocumentDb库。添加nuget包后,是否需要手动添加引用?我认为使用nuget会自动添加项目引用。
答
根据你的另一个SO thread,似乎你使用.net project而不是.net core项目。
.NET Framework提供了一个全面的编程模型,用于在Windows上构建各种应用程序,从移动到Web到桌面。
请尝试创建一个.net核心项目。 我们可以从nuget获得Microsoft.Azure.DocumentDB.Core。我测试在windows平台上用.net核心项目创建文档。它在我身边正常工作。我认为它也应该可以在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; }
}
我们也可以从document获得更多的文件示例代码。