Yair Halberstadt
Yair Halberstadt

Reputation: 6841

Why do I sometimes need to add a nuget package to the actual project that's being run

I have a solution with a large number of projects, some of them .Net Framework 4.7.2, some of them .Net Standard 2.0.

Of course we use a large number of Nuget packages, and usually everything works fine.

Sometimes though, I add a Nuget package to a project, and the solution will build fine. However when I run the tests, or the actual application I get a runtime System.IO.FileNotFound exception, stating that it can't find the dll for the nuget package.

When I also add the nuget package to the test project, or the project containing the application, everything works fine.

For example, just now I was converting a project from .Net Framework to .Net Standard, so I removed Irony.Interpreter and replaced it with Irony.Interpreter.NetCore.

However all my tests suddenly started failing, claiming they couldn't find the nuget package. When I added Irony.Interpreter.NetCore to the test project though, the tests all passed. Note that the test project is .Net Framework, and never previously referenced Irony.Interpreter.

Does anyone have any idea why this might be occurring?

Upvotes: 2

Views: 36

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156988

The compiler only checks the existence of types (for example classes, structs and enums) used in your code. If you don't call it, the compiler will not complain.

However, those dependencies might need other assemblies in order to run (they were compiled using those assemblies as reference). Those second-degree dependencies are often not caught by the compiler (they will when a type from that dependency is exposed).

Upvotes: 1

Related Questions