Install a Nuget package in Visual Studio Code

后端 未结 10 1680
自闭症患者
自闭症患者 2020-12-02 05:16

How can I install a Nuget Package in Visual Studio Code? I know in Visual Studio, we can do this through the Nuget Package Manager console, but how do I do it in VS Code?

相关标签:
10条回答
  • 2020-12-02 05:57

    If you're working with .net core, you can use the dotnet CLI, for instance

    dotnet add package <package name>
    
    0 讨论(0)
  • 2020-12-02 06:00

    From the command line or the Terminal windows in vs code editor dotnet add package Newtonsoft.Json

    See this article by Scott Hanselman

    0 讨论(0)
  • 2020-12-02 06:01

    Nuget Gallery provides a GUI similar to the full Visual Studio. See below.

    How To Use:

    1. Install Nuget Gallery from extension marketplace.
    2. Launch from the menu bar View > Command Palette or ⇧⌘P (Ctrl+Shift+P on Windows and Linux). Type Nuget: Open Gallery.
    3. The GUI above is displayed. You can filter just like in regular Visual Studio.
    4. Make sure the .csproj file checkbox is selected, select version from dropdown, and click install button.

    UPDATE

    Earlier versions, as noted in the comments, had an issue where the .csproj checkbox was not visible when a package in the csproj file was missing a version number like below.

    <PackageReference Include="Microsoft.AspNetCore.App" />
    

    This has been fixed in newer versions of the extension so if you have an older version with this issue, please update it to the latest version.

    0 讨论(0)
  • 2020-12-02 06:02

    You can use the NuGet Package Manager extension.

    After you've installed it, to add a package, press Ctrl+Shift+P, and type >nuget and press Enter:

    Type a part of your package's name as search string:

    Choose the package:

    And finally the package version (you probably want the newest one):

    0 讨论(0)
  • 2020-12-02 06:02
    1. Install NuGet Package Manager
    2. Ctrl+Shift+P on Windows or Command+Shift+P on Mac
    3. Search for NuGet Package Manager: Add Package
    4. Enter package name i.e. AutoMapper
    5. Select package & version
    6. Restore if needed
    0 讨论(0)
  • 2020-12-02 06:03

    Modify your project.json or *.csproj file. Add a dependency entry with the name of the package and the version desired.

    JSON example:

    {
       "dependencies" : {
    
         "AutoMapper": "5.2.0"
       }
    }
    
    0 讨论(0)
提交回复
热议问题