【问题标题】:How to add external assembly (.dll) to .NET Core 2.0 on Visual Studio Code如何在 Visual Studio Code 上将外部程序集 (.dll) 添加到 .NET Core 2.0
【发布时间】:2017-10-18 17:03:06
【问题描述】:

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

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

【问题讨论】:

    标签: c# visual-studio-code asp.net-core-2.0


    【解决方案1】:

    右键项目 添加现有项目 > 选择 .dll 的路径 在项目中添加dll后,右键单击.dll

    build-action = Content, Copy-to-output-dir = Always/ 或者如果更新

    【讨论】:

      【解决方案2】:

      Visual Studio 社区 2019 [v16.8.4]

      1. 右键单击您的 aspnetcore 项目
      2. Project Reference... > 浏览 > Browse...
      3. 找到并Add您的 DLL 文件

      【讨论】:

      • Visual Studio Community 和 Visual Studio Code 不一样,问题问的是什么。
      • 哦!谢谢,我没有意识到这个问题是关于 VS Code 的!
      【解决方案3】:

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

      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 移动到项目的 文件夹(Program.cs 所在的位置)

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

      3. 然后,执行dotnet run

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

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

      【讨论】:

      • 我今天在使用 .net core 2.0 应用程序时遇到了类似的问题。我的解决方法是创建一个新的 .net 框架 web 应用程序(不是 .net 核心)并在那里添加引用。然后我将项目组从 csproj 复制到我的 .net 核心项目的 csproj 文件中。成功了。
      • 你提到在下面添加代码的地方 我必须在标签上方添加才能让 dotnet restore 正常工作,不确定是不是我做错了。
      • 谢谢,您帮助我解决了 Xamarin 项目和 AppCenter 的问题!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2020-08-10
      • 1970-01-01
      • 2017-10-04
      相关资源
      最近更新 更多