如何使用 Visual Studio Code 从 .NET Core 访问 Nuget 存储库 [英] How to access Nuget repository from .NET Core using Visual Studio Code

查看:29
本文介绍了如何使用 Visual Studio Code 从 .NET Core 访问 Nuget 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和一位朋友一起从事 .NET Core 项目,我们正在按照我们认为最好的方式拆分工作.我们目前正在尝试配置要与之通信的数据库应用程序,因此我们需要一个数据库驱动程序"库.

I'm working on a .NET Core project with a friend and we're splitting the work as we see best. We're currently trying to configure a database application to communicate with so we need a database "driver" library.

我决定使用 MongoDB,并且找到了这个页面这似乎表明以下代码将以某种方式配置我们的项目以使用该库.选择 .NET Core 和 Nuget(我已经在本地和我们的服务器上安装了它们),我得到以下代码,这似乎是添加库的方法:

I've decided on MongoDB, and I've found this page which seems to suggest that the following code will configure our project somehow to use the library. Selecting .NET Core and Nuget (both of which I've installed locally and on our server), I get the following code which seems to be the way to add the library:

<packages>
    <package id="MongoDB.Driver.Core" version="2.3.0" />
    <package id="MongoDB.Bson" version="2.3.0" />
</packages>

问题是,我不知道如何使用它,也不知道在哪里使用它.我正在查看的配置文件几乎完全是 json.我的印象是这实际上是为与 Visual Studio 一起使用而设计的,因为它的项目文件仍然使用 XML.

The problem is, I've no idea how nor where to use this. The configuration files I'm looking at are almost entirely json. I get the impression this was actually designed to be used with Visual Studio since its project files still use XML.

那么问题是:如何使用 Visual Studio Code 从外部库中导入函数以进行 .NET Core 开发?我怀疑我只需要将其转换为合适的格式 (JSON) 就可以了,但我不确定它会是什么样子,也不知道它应该存放在哪个文件中.

So the question: How do I import functions from an external library for .NET Core development using Visual Studio Code? I suspect I just need to translate this into a suitable format (JSON) and that'll do, but I'm not sure what it's going to look like nor which file it's supposed to live in.

我尝试通过打开快速菜单,输入选择 >Nuget: Add Package,然后找到并选择包 MongoDB.Driver.Core 来执行此操作,但这会导致错误消息:

I've tried to do this by opening the quick-menu, entering selecting >Nuget: Add Package, then finding and selecting the package MongoDB.Driver.Core, but this results in the error message:

Could not read project.json, please try again.

我不完全理解这一点,我怀疑可能是项目的根级别需要 project.json,在我的情况下不是这样,但这并不完全有意义.

I don't entirely understand this, I suspect it may be that project.json is required at the root level of the project, which it is not in my case, but this doesn't entirely make sense.

推荐答案

这是一个旧帖子,但想分享,因为我正在寻找相同的:由于您已经有一个正在处理 VSCode 的 .NET 项目,因此您可以使用dotnet"像这样的命令:

This is an old post, but would like to share because I was looking for the same: As you already have a .NET project that you are working on VSCode, then you can use the "dotnet" command like this:

dotnet add package MongoDB.Driver --version 2.11.6

这篇关于如何使用 Visual Studio Code 从 .NET Core 访问 Nuget 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆