Nuget reference from unreferenced class library

Magne 126 Reputation points
2021-11-04T21:07:30.35+00:00

I have a .Net 5 WPF project and a few .Net 5 class library projects.
The class library projects are not referenced directly from the WPF assembly because the class libraries are meant to be loaded in runtime by the wpf app.
This works fine by using interfaces defined in a common lib (referred to from both wpf assembly and relevant class libraries.

If I then add a nuget dependency to one of the class library projects, the assembly in the nuget package is not copied anywhere.
I expected that to be copied to the same directory as the respective class library dll file is written to (where-ever this is set to be by the OutputPath property of the csproj file)

Something I misunderstand or is this a bug?
Is the only possibility (a quite "dirty" one, but it works) to copy the referenced assembly from the nuget package to the output folder by post build event?

(To be a bit specific, I am using Prism and DirectoryModuleCatalog for loading the class libraries)

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,367 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
{count} votes

Accepted answer
  1. Magne 126 Reputation points
    2021-11-05T10:21:07.19+00:00

    Ok, more searches and found this: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#copylocallockfileassemblies

    Have a look at the CopyLocalLockFileAssemblies property which solved the problem for me (could remove the specific xcopy in post-build actions)
    Note that this property (and probably a bunch of others) is not available at the page when right clicking the project and select Properties, you must edit the project file.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Magne 126 Reputation points
    2021-11-05T09:55:49.58+00:00

    Thanks, however I don't see how your link relates to my problem at all.

    Further Prism was just mentioned as a side-note, the problem has nothing to do with Prism or any other 3rd part libraries, but in general to the concept of run-time loading of assemblies (Prism with DirectoryModuleCatalog just happens to do this)

    0 comments No comments

  2. Bruce (SqlWork.com) 55,601 Reputation points
    2021-11-05T14:34:30.297+00:00

    It may be a bug with the nuget package internal configuration. The builder of the nuget package controls what dlls are copied local by default.

    Maybe the package has optional dlls and you are expect to add a reference.