Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add assembly references in Visual Studio Code?

So I've come across a similar issue twice now while working on my first project in C#. When trying to add either using System.Data; or using System.Timers;, I get the following error:

The type or namespace name 'x' doesn't exist in the namespace 'System' (are you missing an assembly reference?).

I have tried beginning a new project and running restore to see if I had accidentally removed something in the dependencies, but upon generating a new project I still receive the same error. I have tried to research the question and have seen answers referring to the 'solutions explorer', but as far as I can see there doesn't seem to be such a feature by this name in Visual Studio Code 1.8.

Can anyone point me in the right direction for how to get these working, perhaps by manually adding into the dependencies?

like image 425
jamessct Avatar asked Feb 02 '17 11:02

jamessct


People also ask

How do I add assembly in Visual Studio?

To add an assembly from project outputOpen the Package Designer. For more information, see How to: Customize a SharePoint solution package. Choose the Advanced tab. Choose the Add button, and then choose Add Assembly from Project Output from the list.


1 Answers

.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

  1. Install Visual Studio Code
  2. Install .NET Core SDK (Preview 2 version)
  3. Install NuGet Package Manager from the Visual Studio Code Extension Marketplace
  4. Install C# extension from Visual Studio Code Extension Marketplace

Steps

  1. Launch Visual Studio Code
  2. Open your project folder
  3. Launch VS Code Command Palette by pressing F1 or Ctrl+Shift+P or Menu Bar > View > Command Palette

enter image description here

  1. In Command Palette box, type nu

enter image description here

  1. Click on NuGet Package Manager: Add Package

  2. Enter package filter e.g. system.data (Enter your assembly reference here)

enter image description here

  1. Press Enter
  2. Click on System.Data.SqlClient

enter image description here

  1. The following prompt pops up

enter image description here

  1. Click on Restore

enter image description here

  1. The following Output panel pops up

enter image description here

  1. In the Explorer panel, click on project.json to open it

enter image description here

  1. In the Editor panel, it shows the assembly reference added into project.json file

enter image description here

  1. Assembly reference, System.Data.SqlClient used in Program.cs

enter image description here

like image 146
ikolim Avatar answered Oct 04 '22 15:10

ikolim