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

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

问题描述

由于在 Visual Studio Code 上的.NET Core 2.0控制台应用程序中添加了外部程序集(.dll),我遇到了一些问题,因为关于如何执行此操作的文档很少./p>

Microsoft提供了关于如何将NuGet Packages和Project添加到项目引用的很好的教程,但是没有有关如何添加外部dlls的信息.

解决方案

经过研究,我设法使其正常运行.

  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> 

  1. dll移至项目的 root 文件夹(其中Program.cs所在)

  2. 使用控制台/终端导航到项目的 root 文件夹,并执行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天全站免登陆