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
I've found one approach that seems like it will work.
- In the content folder in the Nuget package place the dlls to be scanned in a temp folder.
- 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
- 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
Company.Dal Company.Dal.Ninject Company.Dal.StructureMap
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.
- It will get the job done.
- Having to copy dlls to all installed projects and then delete them
- 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/
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:
<files> <file src="output\Implementation.dll" target="output\Implementation.dll" /> <file src="lib\Implementation.Contract.dll" target="output\Implementation.Contract.dll" /> </files>
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