gpt4 book ai didi

c# - 如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0

转载 作者:太空狗 更新时间:2023-10-29 17:45:46 28 4
gpt4 key购买 nike

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

Microsoft 提供了一个 very good tutorial关于如何将 NuGet Packages 和 Project 添加到项目引用,但没有关于如何添加外部 dll 的信息。

最佳答案

经过一些研究,我设法让它工作。

  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. 使用控制台/终端导航到项目的 文件夹并执行dotnet restore导入所有引用

  3. 然后,执行dotnet run

  4. 不要从您的根文件夹中删除 dll。如果这样做,您将收到以下错误:

error CS0246: The type or namespace name 'Your dll File' could not be found (are you missing a using directive or an assembly reference?)

关于c# - 如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46815546/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com