简体   繁体   English

如何使用 Visual Studio Code 从 .NET Core 访问 Nuget 存储库

[英]How to access Nuget repository from .NET Core using Visual Studio Code

I'm working on a .NET Core project with a friend and we're splitting the work as we see best.我正在和一位朋友一起从事 .NET Core 项目,我们正在按照我们认为最好的方式拆分工作。 We're currently trying to configure a database application to communicate with so we need a database "driver" library.我们目前正在尝试配置一个数据库应用程序来与之通信,因此我们需要一个数据库“驱动程序”库。

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

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

The problem is, I've no idea how nor where to use this.问题是,我不知道如何使用它,也不知道在哪里使用它。 The configuration files I'm looking at are almost entirely json.我正在查看的配置文件几乎完全是 json。 I get the impression this was actually designed to be used with Visual Studio since its project files still use XML.我的印象是这实际上是为与 Visual Studio 一起使用而设计的,因为它的项目文件仍然使用 XML。

So the question: How do I import functions from an external library for .NET Core development using Visual Studio Code?所以问题是:如何使用 Visual Studio Code 从外部库导入函数以进行 .NET Core 开发? 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.我怀疑我只需要将其转换为合适的格式 (JSON) 就可以了,但我不确定它会是什么样子,也不知道它应该存放在哪个文件中。

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:我尝试通过打开快速菜单,输入选择>Nuget:添加包,然后查找并选择包 MongoDB.Driver.Core 来执行此操作,但这会导致错误消息:

Could not read project.json, please try again.

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.我不完全理解这一点,我怀疑可能是项目的根级别需要 project.json ,这不是我的情况,但这并不完全有意义。

I've tried creating a new project, it looks like there is a bug that Code expects project.json to be at the root of the open folder (which it is not).我试过创建一个新项目,它看起来有一个错误,代码希望 project.json 位于打开文件夹的根目录(它不是)。 The end solution for me was to add "MongoDB.Driver.Core": "2.3.0" to the project.json file, so it now looks like so (this is a default project.json with the added bit):我的最终解决方案是将"MongoDB.Driver.Core": "2.3.0"到 project.json 文件,所以现在看起来像这样(这是一个带有添加位的默认 project.json):

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {
    "MongoDB.Driver.Core": "2.3.0"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

Update:更新:

Right now before .NET Core 2.0 I use in Visual Studio Code Nuget Package Extension.现在在 .NET Core 2.0 之前,我在 Visual Studio Code Nuget 包扩展中使用。 You can download this extension via Extension tools in VSC or from URL:您可以通过 VSC 中的扩展工具或从 URL 下载此扩展:

https://marketplace.visualstudio.com/items?itemName=jmrog.vscode-nuget-package-manager https://marketplace.visualstudio.com/items?itemName=jmrog.vscode-nuget-package-manager

To use this extension use CTRL + SHIFT + P and then type Nuget Package Manager: Add Package and then download what you want :) !要使用此扩展,请使用CTRL + SHIFT + P ,然后键入Nuget Package Manager: Add Package ,然后下载您想要的内容:)!

这是一篇旧帖子,但想分享一下,因为我一直在寻找相同的内容:由于您已经有一个正在使用 VSCode 的 .NET 项目,因此您可以使用“dotnet”命令,如下所示:

dotnet add package MongoDB.Driver --version 2.11.6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用.NET CORE安装NuGet软件包和Visual Studio代码失败 - Install NuGet package with .NET CORE and visual studio code failed 如何使用NuGet在Visual Studio 2012上安装protobuf-net? - How to install protobuf-net on Visual Studio 2012 using NuGet? 如何使用Visual Studio代码将实体框架核心安装到asp.net核心3项目 - How to install entity framework core to asp.net core 3 project using visual studio code 引用 a.Net Core 3.1 NuGet package 的 a.Net 5 Visual Studio 项目/解决方案如何编译成功? - How can a .Net 5 Visual Studio Project / Solution that reference a .Net Core 3.1 NuGet package compile successfuly? 如何从 asp.net 核心 5.0 中实体核心中的数据库更新 Visual Studio 代码中的模型 - How to update models in visual studio code from database in Entity Core in asp.net core 5.0 Visual Studio 2017仅具有适用于.NET Core 2.x的脱机Nuget包。如何获得在线套餐? - Visual Studio 2017 only has offline Nuget Packages for .NET Core 2.x. How to get online packages? 如何在 Visual Studio 中为 nuget 包创建离线存储库 - How to create an offline repository for nuget packages in Visual Studio 如何使用 Visual Studio 2019 在 azure function 编写的 .net 核心 3.1 的捕获块中捕获状态代码 2019 - How to capture status code in catch block of an azure function written .net core 3.1 using visual studio 2019 如何使用 Visual Studio 代码为 .NET Core 的工作人员服务创建安装程序 - How to create an installer for worker service of .NET Core using visual studio code Visual Studio代码-.NET Core测试资源管理器 - Visual Studio Code - .NET Core Test Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM