[英]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#.所以我现在在 C# 中处理我的第一个项目时遇到了两次类似的问题。 When trying to add either using System.Data;
尝试using System.Data;
添加时using System.Data;
or using System.Timers;
或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?).命名空间“System”中不存在类型或命名空间名称“x”(您是否缺少程序集引用?)。
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.我尝试开始一个新项目并运行restore
以查看我是否不小心删除了依赖项中的某些内容,但是在生成新项目时我仍然收到相同的错误。 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.我试图研究这个问题,并看到了关于“解决方案资源管理器”的答案,但据我所知,在 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?任何人都可以指出我如何让这些工作的正确方向,也许是通过手动添加到依赖项中?
The following topic applies to .csproj
project file and : .NET Core 1.x SDK, .NET Core 2.x SDK以下主题适用于.csproj
项目文件和:.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:将Newtonsoft.Json
NuGet 包添加到项目中:
dotnet add package Newtonsoft.Json
The following topic applies to .json
project file:以下主题适用于.json
项目文件:
This guide walks you through the process of adding any assembly reference in Visual Studio Code.本指南将引导您完成在 Visual Studio Code 中添加任何程序集引用的过程。 In this example, we are adding the assembly reference System.Data.SqlClient into .NET Core C# console application.在此示例中,我们将程序集引用System.Data.SqlClient添加到 .NET Core C# 控制台应用程序中。
Note笔记
Prerequisites先决条件
Steps脚步
Click on NuGet Package Manager: Add Package单击NuGet 包管理器:添加包
Enter package filter eg system.data ( Enter your assembly reference here )输入包过滤器,例如system.data (在此处输入您的程序集参考)
Use the command dotnet add package
to add a package reference to your project.使用命令dotnet add package
向项目添加包引用。 For example: dotnet add package Newtonsoft.Json
, which adds the package reference to the *.csproj
project file:例如: dotnet add package Newtonsoft.Json
,它添加了对*.csproj
项目文件的包引用:
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
and now you can run the command dotnet restore
to restores the dependencies of your project.现在您可以运行命令dotnet restore
来恢复项目的依赖项。
Reference: dotnet add package参考: dotnet 添加包
Above answer from ikolim doesnt work as indicated by someone else too, there is no, Nuget: Install/Reference command.上面来自 ikolim 的答案也没有按照其他人的指示工作,没有,Nuget: Install/Reference 命令。 There is only Add Package!只有添加包! So the answer in the below link solved my problem.所以下面链接中的答案解决了我的问题。 Manually editing the Myproject.csproj file.手动编辑 Myproject.csproj 文件。
In case of extisting .dll reference, Right click project Add existing item > select path to .dll After added dll in project,right click .dll如果存在 .dll 引用,请右键单击项目 添加现有项目 > 选择 .dll 的路径 在项目中添加 dll 后,右键单击 .dll
build-action = Content, Copy-to-output-dir = Always/ or if newer build-action = Content, Copy-to-output-dir = Always/ 或者如果更新
I've stored the files in a project folder named "dlls" and added the reference files in my .csproj file like this:我将文件存储在名为“dlls”的项目文件夹中,并在我的 .csproj 文件中添加了参考文件,如下所示:
<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>
So I've come across a similar issue twice now while working on my first project in C#.因此,在使用C#进行第一个项目时,我遇到了两次类似的问题。 When trying to add either using System.Data;
尝试using System.Data;
添加时using System.Data;
or using System.Timers;
或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?).类型或名称空间名称“ x”在名称空间“系统”中不存在(您是否缺少程序集引用?)。
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.我尝试开始一个新项目并运行restore
以查看是否意外删除了依赖项中的某些内容,但是在生成新项目时,我仍然收到相同的错误。 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.我试图研究该问题,并看到了涉及“解决方案资源管理器”的答案,但是据我所知,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?有人可以通过手动添加依赖项为我指出如何使它们正常工作的正确方向吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.