如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0 [英] How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code

查看:19
本文介绍了如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将外部程序集 (.dll) 添加到 Visual Studio Code 上的 .NET Core 2.0 控制台应用程序时,我遇到了一些问题几乎没有关于如何做到这一点的文档.

微软提供了一个关于如何将 NuGet Packages 和 Project 添加到项目引用的非常好的教程,但没有关于如何添加外部 dll 的信息.

解决方案

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

  1. 打开你的 .csproj 文件

  2. 标签下方,添加

<Reference Include="您的 dll 文件名"><HintPath>你的dll文件名.dll</HintPath><SpecificVersion>False</SpecificVersion><!-- 如果您的 dll 具有特定版本,您可以将其设置为 true --></参考></ItemGroup>

  1. dll 移动到项目的 root 文件夹(Program.cs 所在的位置)

  2. 使用控制台/终端导航到项目的文件夹并执行dotnet restore以导入所有引用

  3. 然后,执行dotnet run

  4. 不要不要从根文件夹中删除 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.

  1. Open your .csproj file

  2. Below </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>

  1. Move the dll to the root folder of your project (where Program.cs is)

  2. Navigate to the root folder of your project using console/terminal and execute dotnet restore to import all the references

  3. Then, execute dotnet run

  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆