如何在Visual Studio代码上将外部程序集(.dll)添加到.NET Core 2.0

Gia*_*cca 10 c# visual-studio-code asp.net-core-2.0

我遇到了一些关于在Visual Studio Code.dll向我的.NET Core 2.0控制台应用程序添加外部程序集()的问题,因为几乎没有关于如何执行此操作的文档.

Microsoft提供了一个非常好的教程,介绍如何添加NuGet Packages和Project项目引用,但没有关于如何添加外部的信息dlls.

Gia*_*cca 13

经过一番研究,我设法让它发挥作用.

  1. 打开你的.csproj文件

  2. </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>
Run Code Online (Sandbox Code Playgroud)

  1. 移动dll到项目的文件夹(在哪里Program.cs)

  2. 使用console/terminal 导航到项目的文件夹,然后执行dotnet restore以导入所有引用

  3. 然后,执行 dotnet run

  4. 难道不是从你的根文件夹中删除DLL.如果这样做,您将收到以下错误:

错误CS0246:找不到类型或命名空间名称"您的DLL文件"(您是否缺少using指令或程序集引用?)