3

In my solution I have a top level project with a bunch of dependent projects. One of the dependent projects has a required reference to the Nest nuget package. So in our nuget package config for the solution, I have Nest installed only on the project that references it.

The top level project has a reference to this dependent project, but no references to the Nest namespace. It builds without warnings or errors, however, in runtime, I have an issue saying

Could not load file or assembly 'Nest, Version=7.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d' or one of its dependencies. The system cannot find the file specified.

When I manually install the Nest package on my top level project, it succeeds without issue.

Why does this occur? Shouldn't installing the Nest package on the dependent project resolve this dependency?

Steve Pak
  • 152
  • 1
  • 13
  • You need to add that nuget manually as it seems the dependency that does need it is not adding it and the dll is not found at run time. – Matt Nov 07 '19 at 22:21
  • The project that fails at runtime, what type of project is it? netcoreapp, or .net framework? sdk style project, or "traditional" non-sdk style? – zivkan Nov 08 '19 at 00:21
  • Hi Steve, what's your vs version? And what project type do you use? .net core reference .net standard or .net framework reference .net standard? The behavior changes a lot with different vs versions and different target framework... – LoLance Nov 11 '19 at 06:14
  • You can try #2 and #4 in my answer, hope that helps to resolve your issue. Feel free to let me know it it helps or not :) – LoLance Nov 11 '19 at 06:29

1 Answers1

7

One of the dependent projects has a required reference to the Nest nuget package.

Did you call Nest's function in the dependent project? VS will not copy the dependent project's assembly into top-level project if it finds the dependent project doesn't actually call(need) the assembly in code.

Why does this occur? Shouldn't installing the Nest package on the dependent project resolve this dependency?

I'm not sure the cause of the issue with info available in your question, many factors can cause the strange behavior and sometimes VS version would also affect it...

Assuming you have a top-level project A and it depends on project B using Project Reference.

1.If both them targets .net framework, please make sure they use the same way to manager nuget packages.(Both using packages.config or both using PackageReference)

2.If A is .net framework project while B is .net standard project, please make sure the A is also using PackageReference format to manage nuget packages.

Cause .net standard(new SDK format) uses PackageReference packages, if A uses Packages.config and reference B, the build system will be confused about the different nuget formats in the build process. And we won't find the Nest.dll copied from B's output folder to A's output folder.

For this situation, try adding <RestoreProjectStyle>PackageReference</RestoreProjectStyle> into top-level A's project file.(xx.csproj) It will make sure both A and B can be restored as PackageReference style.

3.If A is .net framework with packageReference, and B is .net framework with Packages.config, right-click the packages.config and choose Migrate Package.config to PackageReference button. Also you may get some help from this document.

4.If your top-level project is .net core and B project targets .net standard, in VS2017, the nest.dll won't be copied into A's output folder, you can try adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to your A.csproj to resolve this issue. Similar issue see here. (And VS2019 16.3.8 has fixed this issue, this issue mostly occurs in VS2017)

And this behavior is also affected by VS version, if you're using VS2017, please update it to latest 15.9.17 for better experience. If you're using VS2019, please update it to 16.3.8.

Hope it helps :)

LoLance
  • 25,666
  • 1
  • 39
  • 73