我正在尝试创建一个简单的 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; }
}
我们还可以从 document 获取更多文档示例代码.
关于c# - 在 Visual Studio Mac 中找不到命名空间 Microsoft.Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44328135/