如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0 [英] How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code
问题描述
在将外部程序集 (.dll
) 添加到 Visual Studio Code 上的 .NET Core 2.0
控制台应用程序时,我遇到了一些问题几乎没有关于如何做到这一点的文档.
微软提供了一个关于如何将 NuGet Packages
和 Project 添加到项目引用的非常好的教程,但没有关于如何添加外部 dll
的信息.
经过一些研究,我设法让它发挥作用.
打开你的
.csproj
文件在
标签下方,添加
<Reference Include="您的 dll 文件名"><HintPath>你的dll文件名.dll</HintPath><SpecificVersion>False</SpecificVersion><!-- 如果您的 dll 具有特定版本,您可以将其设置为 true --></参考></ItemGroup>
将
莉>dll
移动到项目的 root 文件夹(Program.cs
所在的位置)使用控制台/终端导航到项目的根文件夹并执行
dotnet restore
以导入所有引用然后,执行
dotnet run
不要不要从根文件夹中删除 dll.如果这样做,您将收到以下错误:
<块引用>
错误 CS0246:找不到类型或命名空间名称您的 dll 文件"(您是否缺少 using 指令或程序集引用?)
I faced some issues regarding adding an external assembly (.dll
) to my .NET Core 2.0
console application on Visual Studio Code as there are little to none documentation about how you can do it.
Microsoft provides a very good tutorial about how one can add NuGet Packages
and Project to project references, but no information on how to add external dlls
.
After some research I managed to get it working.
Open your
.csproj
fileBelow
</PropertyGroup>
tag, add
<ItemGroup>
<Reference Include="Your dll file name">
<HintPath>Your dll file name.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<!-- You may set it to true if your dll has a specific version -->
</Reference>
</ItemGroup>
Move the
dll
to the root folder of your project (whereProgram.cs
is)Navigate to the root folder of your project using console/terminal and execute
dotnet restore
to import all the referencesThen, execute
dotnet run
Do not remove the dll from your root folder. If you do, you will receive the following error:
error CS0246: The type or namespace name 'Your dll File' could not be found (are you missing a using directive or an assembly reference?)
这篇关于如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!