Cómo copiar archivos de contenido de Nuget en relación con la raíz de la solución

I have created a DAL on my current project which is persistence ignorant and has a contract dll that needs to be directly referenced and then implementation dlls that are meant to be scanned by our IoC container to resolve the ORM specific implementations and mappings that relate\implement the interfaces and POCs defined in the contract dll. My desire is to have the implementation dlls copied to a [solution root]\lib directory. I've created a package and loaded the implementation dlls into the content folder and when installing the package they end up in [project root]\lib.

My question is how can I have Nuget copy my implementation dlls to [solution root]\lib?

preguntado el 04 de julio de 12 a las 00:07

2 Respuestas

I've found one approach that seems like it will work.

  1. In the content folder in the Nuget package place the dlls to be scanned in a temp folder.
  2. Add an Init.ps1 script that will execute only once per solution to the tools folder of the Nuget package (http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package). In this script copy the files to the desired directory [solution dir]\lib
  3. Add an Install.ps1 file to the tools folder that will run once per installed project that will delete the temp folder

I can then create another package for my container registration that depends on my dal package and use a similar approach to setup my IoC registration. So I'd have


and then consumers would install the package that uses the same container that they use and this would take care of installing the needed dlls to [solution dir]\lib and configure the container to consume these dlls.


  1. It will get the job done.


  1. Having to copy dlls to all installed projects and then delete them
  2. Init.ps1 also runs every time that the solution is opened

Editar @MrMVCMan, I went ahead and created a blog post documenting how I did this here: http://www.ryanvice.net/nuget/creating-a-nuget-package-that-will-install-files-relative-to-the-solution/

Respondido el 28 de Septiembre de 13 a las 20:09

403 on link. I consider the answer incomplete - Madhav Shenoy

Couldn't find on wayback either - vivalapanda

I've create a generic nuget package which solves your problem but with a different approach. Instead of copying the packages into a lib Folder, it copies them at build time to the build output folder.

Your nuspec file could look something like this:

    <file src="output\Implementation.dll" target="output\Implementation.dll" />
    <file src="lib\Implementation.Contract.dll" target="output\Implementation.Contract.dll" />

When adding this nuget package to Project the Implementation.Contract.dll get's added as reference to the Project but the Implementation is not added to the project.

For an complete example read my blog at: http://www.baseclass.ch/blog/Lists/Beitraege/Post.aspx?ID=6&mobile=0

Respondido 18 Jul 14, 09:07

Thanks Daniel, your extension to NuGet works perfectly: files are copied to the output folder and not added as a reference. Cheers! - flobadob

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.