Reputation: 991
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?
Upvotes: 69
Views: 217936
Reputation: 231
I've stored the files in a project folder named "dlls" and added the reference files in my .csproj file like this:
<ItemGroup> <Reference Include="Microsoft.Office.Client.Policy.Portable"> <HintPath>dlls\Microsoft.Office.Client.Policy.Portable.dll</HintPath> </Reference> <Reference Include="Microsoft.Office.Client.TranslationServices.Portable"> <HintPath>dlls\Microsoft.Office.Client.TranslationServices.Portable.dll</HintPath> </Reference> </ItemGroup>
Upvotes: 3
Reputation: 309
In case of extisting .dll reference, Right click project Add existing item > select path to .dll After added dll in project,right click .dll
build-action = Content, Copy-to-output-dir = Always/ or if newer
Upvotes: -2
Reputation: 16041
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
Add Newtonsoft.Json
NuGet package to a project:
dotnet add package Newtonsoft.Json
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
Prerequisites
Steps
Click on NuGet Package Manager: Add Package
Enter package filter e.g. system.data (Enter your assembly reference here)
Upvotes: 93
Reputation: 350
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.
Upvotes: 2
Reputation: 5442
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
Upvotes: 9