如何在Visual Studio Code上将外部程序集(.dll)添加到.NET Core 2.0 [英] How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code
问题描述
由于在 Visual Studio Code 上的.NET Core 2.0
控制台应用程序中添加了外部程序集(.dll
),我遇到了一些问题,因为关于如何执行此操作的文档很少./p>
Microsoft提供了关于如何将NuGet Packages
和Project添加到项目引用的很好的教程,但是没有有关如何添加外部dlls
的信息.
经过研究,我设法使其正常运行.
-
打开您的
.csproj
文件 -
在
</PropertyGroup>
标签下面,添加
<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>
-
将
dll
移至项目的 root 文件夹(其中Program.cs
所在) -
使用控制台/终端导航到项目的 root 文件夹,并执行
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屋!