How do I add assembly references in Visual Studio Code?
drag the dll file and drop it into the bin folder
.csproj Project file
The following topic applies to .csproj
project file and : .NET Core 1.x SDK, .NET Core 2.x SDK
Adds a package reference to a project file.
dotnet add package
Example
Add Newtonsoft.Json
NuGet package to a project:
dotnet add package Newtonsoft.Json
.json Project file
The following topic applies to .json
project file:
This guide walks you through the process of adding any assembly reference in Visual Studio Code. In this example, we are adding the assembly reference System.Data.SqlClient into .NET Core C# console application.
Note
- At step #6, enter the assembly reference that you want.
- Some assembly reference is applicable to .NET Framework and it will gives you error(s).
- OleDb is not available in .NET Core, probably because it's not cross platform.
Prerequisites
- Install Visual Studio Code
- Install .NET Core SDK (Preview 2 version)
- Install NuGet Package Manager from the Visual Studio Code Extension Marketplace
- Install C# extension from Visual Studio Code Extension Marketplace
Steps
- Launch Visual Studio Code
- Open your project folder
- Launch VS Code Command Palette by pressing F1 or Ctrl+Shift+P or Menu Bar > View > Command Palette
- In Command Palette box, type nu
Click on NuGet Package Manager: Add Package
Enter package filter e.g. system.data (Enter your assembly reference here)
- Press Enter
- Click on System.Data.SqlClient
- The following prompt pops up
- Click on Restore
- The following Output panel pops up
- In the Explorer panel, click on project.json to open it
- In the Editor panel, it shows the assembly reference added into project.json file
- Assembly reference, System.Data.SqlClient used in Program.cs
Above answer from ikolim doesnt work as indicated by someone else too, there is no, Nuget: Install/Reference command. There is only Add Package! So the answer in the below link solved my problem. Manually editing the Myproject.csproj file.
Duplicate of this thread
Use the command dotnet add package
to add a package reference to your project. For example: dotnet add package Newtonsoft.Json
, which adds the package reference to the *.csproj
project file:
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
and now you can run the command dotnet restore
to restores the dependencies of your project.
Reference: dotnet add package