简体   繁体   English

.NET部署项目不使用但引用的dll需要的dll

[英].NET deploying dlls that project does not use but referenced dlls require

So the problem is quite simple: My project references assembly X but not Z. But assembly X does reference assembly Z. Assembly Z updates somewhat frequently, so whenever I build my project, I'd like to get the latest version of Z as well. 所以问题很简单:我的项目引用程序集X但不引用Z。但是程序集X引用了程序集Z。程序集Z经常更新,因此无论何时构建我的项目,我都希望获得最新版本的Z。 。

So far I've come up with 3 options: 到目前为止,我已经提出了3种选择:

  1. reference the assembly Z. This has the advantage of getting the new version, always. 引用程序集Z。这具有始终获取新版本的优势。 But it does pollute the references with something that isn't strictly required in there. 但是,它确实污染了引用,而这些引用并不是严格要求的。
  2. Add a post-build event that copies the required DLL(s) from where they are updated. 添加一个生成后事件,该事件将从所需的DLL复制到更新后的位置。 I think this is quite ok, until I need multiple different DLLs, which would make the script quite long and tedious to maintain. 我认为这很正常,直到我需要多个不同的DLL,这将使脚本维护起来很长且乏味。
  3. Add the assembly Z as a resource and set copy to output to true. 将程序集Z添加为资源,并将复制副本设置为true。 This one I would probably prefer, except that when I add the DLL to the project, visual studio actually copies the (then) current version in to the project, and there is no link to the original source. 我可能更喜欢这个版本,除了当我将DLL添加到项目中时,Visual Studio实际上将(当时)当前版本复制到项目中,并且没有指向原始源的链接。 Thus, when the assembly is updated, this is not reflected in any way in my project. 因此,在更新程序集时,这不会以任何方式反映在我的项目中。 Unless I combine this approach with option number 2, but then I might as well just use option 2 alone. 除非我将此方法与选项2结合使用,否则不妨仅单独使用选项2。

So, am I missing something, or are these my only options? 那么,我是否缺少某些东西,还是我唯一的选择?

I would go with option 1. I think it's entirely reasonable for your project to reference everything it depends on, even if those dependencies can sometimes be indirect. 我会选择选项1。我认为即使引用有时是间接的,对于您的项目来说,引用它所依赖的所有内容也是完全合理的。

It also seems like the simplest option to me - and one which fits in with Visual Studio's view of code dependencies that your app requires... so anything that Visual Studio does with those dependencies should just naturally flow, rather than you having to think about this at every stage. 在我看来,这似乎是最简单的选择-并且与Visual Studio的应用程序所需的代码依赖关系视图相适应...因此,Visual Studio对这些依赖关系所做的任何事情都应该自然而然地产生,而不是您必须考虑在每个阶段。

EDIT: As an alternative option, have you considered using NuGet ? 编辑:作为替代选项,您是否考虑过使用NuGet That way you'd only express a dependency on X within your project's NuGet dependencies, but it would "know" that it depended on Z. I believe it should all just work... You should be able to do this even if these are internal projects, as you can set your own NuGet source rather than the public repository. 这样,您需要在项目的NuGet依赖关系中表达对X的依赖关系,但就可以“知道”它依赖于Z。我相信它都应该可以工作...即使这些都可以,您也应该能够做到这一点内部项目,因为您可以设置自己的NuGet源而不是公共存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM