Install a Nuget package in Visual Studio Code

后端 未结 10 1681
自闭症患者
自闭症患者 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 06:09

    Open extensions menu (Ctrl+Shift+X), and search .NuGet Package Manager.

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

    The answers above are good, but insufficient if you have more than 1 project (.csproj) in the same folder.

    First, you easily add the "PackageReference" tag to the .csproj file (either manually, by using the nuget package manager or by using the dotnet add package command).

    But then, you need to run the "restore" command manually so you can tell it which project you are trying to restore (if I just clicked the restore button that popped up, nothing happened). You can do that by running:

    dotnet restore Project-File-Name.csproj
    

    And that installs the package

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

    Example for .csproj file

      <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
        <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="7.0.7-m61" />
      </ItemGroup>
    

    Just get package name and version number from NuGet and add to .csproj then save. You will be prompted to run restore that will import new packages.

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

    You can do it easily using "vscode-nuget-package-manager". Go to the marketplace and install this. After That

    1) Press Ctrl+P or Ctrl+Shift+P (and skip 2)

    2) Type ">"

    3) Then select "Nuget Package Manager:Add Package"

    4) Enter package name Ex: Dapper

    5) select package name and version

    6) Done.

    0 讨论(0)
提交回复
热议问题