在.NET Core项目中引用外部DLL [英] Reference external DLL in .NET Core project

查看:153
本文介绍了在.NET Core项目中引用外部DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自己的.dll文件,该文件曾经与Node.js中的Edge.js一起使用,我现在正在尝试将其与点网核心应用程序一起使用,但找不到在何处/如何访问它或对其进行定义.

I've my own .dll file that I used to use with Edge.js in nodejs, I'm trying to use it now with dot net core app, but found no where/no how to get access to it, or define it.

是否有类似

"files":
{
    "":"MyLibrary.dll"
}

或喜欢

using MyLibraryFile.dll

以便我可以使用其中的功能?

so that i can use the functions in it?

我的汇编文件结构为: MyLibraryFile.dll

my assembly file structure is: MyLibraryFile.dll

namespace MyLibrary
{
    public class Inventory
    {
        public async Task<object> Invoke(object input)
    {
}

并且使用MyLbrary; 使用MyLbraryFile; 都无法工作

我需要在MS Code编辑器中使用它,而不是在MS Studio中使用它.并且不想使用 NuGet包

I need to use this with MS Code editor, not with MS Studio. and do not want to use NuGet package

推荐答案

.Net Core 2 支持直接引用外部 .dll (例如,Net Standard库,经典库.Net Framework库).您可以通过Visual Studio UI进行操作:右键单击 Dependencies-> Add reference-> Browse ,然后选择您的外部 .dll .

.Net Core 2 supports a direct reference to external .dll (e.g. Net Standard libraries, classic .Net Framework libraries). You can do it through Visual Studio UI: right click on Dependencies->Add reference->Browse and select your external .dll.

或者,您可以编辑 .csproj 文件:

Alternatively, you can edit .csproj file:

<ItemGroup>
  <Reference Include="MyAssembly">
    <HintPath>path\to\MyAssembly.dll</HintPath>
  </Reference>
</ItemGroup>

您可能会遇到以下错误:

You can face with the following error:

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly

然后只需删除 \ bin 文件夹,即可重建项目.它应该可以解决问题.

then just remove \bin folder an rebuild the project. It should fix the issue.

Net Core 2.0 支持 .Net Standard 2.0 . Net Standard 2.0 提供了

Net Core 2.0 supports .Net Standard 2.0. Net Standard 2.0 provides a compatibility mode to connect .Net Core(.Net Standard) and .NET Framework. It can redirect references e.g. to System.Int32 from mscorlib.dll(Net. Framework) to System.Runtime.dll(Net. Core). But even if your net core app is successfully compiled with dependency on external dll you may still have issues with compatibility during runtime if there is any API used by external library which .Net Standard doesn’t have.

这篇关于在.NET Core项目中引用外部DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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