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

查看:53
本文介绍了如何使用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天全站免登陆