在点网核心中使用外部.dll [英] Using external .dll in dot net core

查看:108
本文介绍了在点网核心中使用外部.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标准库,经典的.Net Framework库)。您可以通过Visual Studio UI进行操作:右键单击 Dependencies->添加引用->浏览并选择您的外部 .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 (。Net标准)和 .NET Framework 。它可以重定向引用例如从 mscorlib.dll (Net。Framework)到 System.Runtime到 System.Int32 。 dll (网络核心)。但是,即使您的网络核心应用程序成功地依赖于外部 dll 进行了编译,但是如果外部库使用了任何.Net标准的API,则在运行时兼容性可能仍然存在问题没有。

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.

这篇关于在点网核心中使用外部.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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