如何复制相对于解决方案根目录的 Nuget 内容文件 [英] How to copy Nuget content files relative to the solution root

查看:67
本文介绍了如何复制相对于解决方案根目录的 Nuget 内容文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我当前的项目上创建了一个 DAL,它是持久性无知的,并且有一个需要直接引用的合同 dll,然后是我们的 IoC 容器扫描的实现 dll,以解决 ORM 特定的实现和映射关联\实现合约 dll 中定义的接口和 POC.我的愿望是将实现 dll 复制到 [solution root]\lib 目录.我创建了一个包并将实现 dll 加载到内容文件夹中,当安装包时,它们最终位于 [项目根目录]\lib 中.

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.

我的问题是如何让 Nuget 将我的实现 dll 复制到 [solution root]\lib?

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

推荐答案

我找到了一种似乎可行的方法.

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

  1. 在 Nuget 包的内容文件夹中,将要扫描的 dll 放在临时文件夹中.
  2. 向 Nuget 包的工具文件夹添加一个 Init.ps1 脚本,该脚本每个解决方案仅执行一次 (http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package).在此脚本中,将文件复制到所需目录 [solution dir]\lib
  3. 将 Install.ps1 文件添加到工具文件夹中,该文件将为每个已安装的项目运行一次,这将删除临时文件夹
  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

然后我可以为我的容器注册创建另一个依赖于我的 dal 包的包,并使用类似的方法来设置我的 IoC 注册.所以我会

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

然后消费者将安装使用他们使用的相同容器的包,这将负责将所需的 dll 安装到 [solution dir]\lib 并配置容器以使用这些 dll.

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. 它会完成工作.

缺点

  1. 必须将 dll 复制到所有已安装的项目,然后将其删除
  2. Init.ps1 也会在每次打开解决方案时运行

编辑@MrMVCMan,我继续创建了一篇博客文章,记录了我在这里是如何做到的:http://www.ryanvice.net/nuget/creating-a-nuget-package-that-will-install-files-relative-to-the-解决方案/

Edit @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/

这篇关于如何复制相对于解决方案根目录的 Nuget 内容文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆