Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

c# - Reference external DLL in .NET Core project

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.

is there something like

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

or like

using MyLibraryFile.dll

so that i can use the functions in it?

my assembly file structure is: MyLibraryFile.dll

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

and neither using MyLbrary; nor using MyLbraryFile;worked

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.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.

Alternatively, you can edit .csproj file:

<ItemGroup>
  <Reference Include="MyAssembly">
    <HintPath>pathoMyAssembly.dll</HintPath>
  </Reference>
</ItemGroup>

You can face with the following error:

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

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

How it is possible

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...