Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget: specify dependency without references being added

Tags:

nuget

I have a package (say, MyStuff.Data) that requires EntityFramework (and others) to work, but only internally. I don't want every project that uses MyStuff.Data to also reference EntityFramework (and all those others), but the dll always needs to be there.

Is there any way I can add EntityFramework as a dependency of MyStuff.Data (so that it picks up EntityFramework.dll in the packages folder), but without a reference being added to each project that consumes it?

like image 293
avesse Avatar asked Apr 26 '12 08:04

avesse


1 Answers

No there is not. An option could be to embed the EntityFramework dll and ship it inside your own package, and explicitly state which references should be added in the target project during installation. You can specify this using the metadata element in the nuspec of you package. More information can be found in the docs here: http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Explicit_Assembly_References

Notice that embedding a specific version of a dependency is a limiting constraint on all your consumers, which means that you, as a package producer, will be driving which version of EF your consumers can and will be using... which is not a good situation to be in.

Preferably, you try to abstract out any non-controlled (EF) dependency and leave the real implementation choice to the consumer (or you provide a separate package containing the implementation, so your consumers can still opt-in and use yours).

like image 66
Xavier Decoster Avatar answered Oct 23 '22 21:10

Xavier Decoster