我有自己的 .dll 文件,我曾经在 nodejs 中使用 Edge.js, 我现在正尝试将它与 dot net core 应用程序一起使用,但没有发现在哪里/没有如何访问它或定义它。
有没有类似的东西
"files":
{
"":"MyLibrary.dll"
}
或者喜欢
using MyLibraryFile.dll
这样我就可以使用里面的功能了?
我的汇编文件结构是:
MyLibraryFile.dll
namespace MyLibrary
{
public class Inventory
{
public async Task<object> Invoke(object input)
{
}
using MyLbrary;
和 using MyLbraryFile;
均无效
我需要将它与 MS Code 编辑器一起使用,而不是与 MS Studio 一起使用。
并且不想使用 NuGet 包
最佳答案
.Net Core 2 支持直接引用外部 .dll
(例如 Net Standard 库、经典 .Net Framework 库)。您可以通过 Visual Studio UI 完成此操作:右键单击 Dependencies->Add reference->Browse
并选择您的外部 .dll
。
或者,您可以编辑 .csproj
文件:
<ItemGroup>
<Reference Include="MyAssembly">
<HintPath>path\to\MyAssembly.dll</HintPath>
</Reference>
</ItemGroup>
您可能会遇到以下错误:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly
然后只需删除 \bin
文件夹并重建项目。它应该可以解决问题。
怎么可能
Net Core 2.0
支持 .Net Standard 2.0
。 Net Standard 2.0
提供了一个 compatibility mode连接 .Net Core
(.Net Standard)和 .NET Framework
。它可以重定向引用,例如从 mscorlib.dll
(Net.Framework) 到 System.Int32
到 System.Runtime.dll
(Net.Core)。但是,即使您的 net core 应用程序在依赖外部 dll
的情况下成功编译,如果外部库使用了 .Net Standard 没有的任何 API,您在运行时可能仍然会遇到兼容性问题。
关于c# - 在 .NET Core 项目中引用外部 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108106/