在 .NET Core 项目中引用外部 DLL [英] Reference external DLL in .NET Core project
问题描述
我有自己的 .dll 文件,我曾经在 nodejs 中与 Edge.js 一起使用,我现在正在尝试将它与 dot net core 应用程序一起使用,但找不到在哪里/没有如何访问它或定义它.
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)
{
}
并且 using MyLbrary;
和 using MyLbraryFile;
都没有工作
and neither using MyLbrary;
nor using MyLbraryFile;
worked
我需要将它与 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 库,classic.Net 框架库).您可以通过 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 oMyAssembly.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
然后只需删除 in
文件夹并重建项目.它应该可以解决问题.
then just remove in
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 Standard) 和.NET Framework
.它可以重定向引用,例如到 System.Int32
从 mscorlib.dll
(Net.Framework) 到 System.Runtime.dll
(Net.Core).但是,即使您的网络核心应用程序成功编译并依赖于外部 dll
,如果外部库使用了任何 .Net Standard 没有的 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.
这篇关于在 .NET Core 项目中引用外部 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!