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

3

7

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.

Kameko answered 26/6, 2018 at 12:11 Comment(2)
I share your pain. It's by design and there's quite som fuss and confusion about it, see github.com/NuGet/Home/issues/4488. 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.Twigg
@Twigg Ouch!!! this really hurts my soul... :( I have a very dirty way to do it, create a .net core application, reference the library and take the results except the exe, but it's totally ugly, Not sure why they did this without an option to "publish" the results... If you add your comment as an answer I will accept it.Kameko
T
3

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.

Twigg answered 26/6, 2018 at 13:20 Comment(0)
A
7

Try:

dotnet publish

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

Aside answered 6/6, 2019 at 14:43 Comment(3)
In Visual Studio 2019, dotnet publish on a class library does NOT output dependencies. The behavior is different from publishing an application.Seema
In Visual Studio 2022 this worked for me on a .Net Standard library. Keep in mind, the output lands in sub directory.Kissel
Can also confirm that this worked in VS2022 for me and the output landed in /bin/Debug/netstandard2.1/publishTerris
T
3

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.

Twigg answered 26/6, 2018 at 13:20 Comment(0)
S
0

TLDR: Convert your Class Library project into an Application, publish the application, and use application DLL as a library.

The long of it:

I tested this approach by deploying 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 your original 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.

Seema answered 8/11, 2021 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.