简体   繁体   中英

Publish .net standard library with all it's dependencies?

I have created a system which loads dynamically a library and executes it's main class. Everything works perfect, the problem I have is how to publish this DLL with all it's dependencies. As no executable project is referencing it I have to manually retrieve the dependencies: try to load the library, check the needed DLL's, go to the NuGet cache folder, copy the libraries, try again, check if it complains about more dependencies and so on until it has all the required libraries.

This is a true pain and I haven't found any information on how to do this, is it possible or am I stuck with this?

The library is a .net standard 2.0 library, I did this before with .net classic and the output folder always contained all the required libraries even the ones comming from a NuGet package, but with .net standard something has changed and now only libraries from referenced projects are being copied, no referenced NuGet package is being copied to the output folder.

Cheers.

At the time of writing, it looks like it's by design and there's quite some fuss and confusion about it, see logged issue on GitHub .

Moreover, when publishing a NuGet package for project A referencing project B,
B becomes a NuGet dependency in A; B's assemby is not included in A's NuGet package.

I deal with it by publishing my own NuGet packages.

I only don't like it to have a NuGet package for project B if that one is only relevant to be used with/by project A, as it will appear seperately in my NuGet feed.

Try:

dotnet publish

All the dependent libraries should be copied to the publish output folder.

Here is a practical, painless solution to publishing DLLs:

So, having fought with this for a bit, I came up with a more elegant solution. I tested this approach and deployed a full build with a plugin with many external dependencies to Ubuntu 18.04 and it ran perfectly.

Create a new project of type Console Application instead of Class Library. Put all your library code files into the Console Application and add the dependencies. Get rid of the Class Library project (you don't need it anymore). Finally, publish the Console Application. You will get a DLL with all of the dependencies. You can use this DLL like any other DLL.

I suggest naming the console app project with "Library" on the end of it and adding a README just to document its not really an application even though the project is configured to build as one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM