Jim Andrakakis
Jim Andrakakis

Reputation: 189

Nuspec: can I have an assembly as a dependency but instruct visual studio to NOT reference it?

I'm developing a set of assemblies which contain classes that, using a dependency injection framework, are supposed to be instantiated only by an "InstanceProvider" class --basically that's my gateway to SimpleInjector's GetInstance(). Then I'm packaging these assemblies as a nuget package.

My goal is to enforce that a developer does

var myDuck = InstanceProvider.GetInstance<IDuck>();

and doesn't do

var myDuck = new Duck();

For this, I have to avoid referencing some of the assemblies, the ones that contain the concrete implementations. I still need them to be there though.

So for now, I have them as dependencies in my nuget package. I'm looking for a way to keep them there, but when a developer uses the package for her project, some of the assemblies should not be directly referenced in their visual studio project.

Is this even possible?

Upvotes: 0

Views: 215

Answers (2)

Leo Liu
Leo Liu

Reputation: 76710

Nuspec: can I have an assembly as a dependency but instruct visual studio to NOT reference it?

Since you do not want to those assemblies directly referenced in their visual studio project when you uses the package for her project, only keep them there. You can set those assemblies in the content files or tools files, like:

<file src="\*.dll" target="content\" />

<file src="\*.dll" target="Tools\" />

Check Creating the .nuspec file for some more details.

With this way, those assemblies included in the nuget package, but those assemblies would not directly referenced to the project when you use the nuget package.

Hope this helps.

Upvotes: 1

Roman Pokrovskij
Roman Pokrovskij

Reputation: 9766

General answer you can, but you should not bother about it till you really need to develop "plugins" enabled system. This turns debugging more complicated.

But continue to devide interface and realization - it is not related to dynamic loading, but helps you to devide code on layers.

There is a lot of DI tools that can this e.g. Unity. The techinque they use: you configure container in xml file that not require referencing. Then container search for assmeblies and load them.

Upvotes: 0

Related Questions