简体   繁体   English

在C#中处理共享dll的最佳方法是什么?

[英]What is the best way to deal with shared dlls in C#?

In my team we have hundreds of shared dlls, which many also reference other dlls that themselves reference other dlls, and so on. 在我的团队中,我们有数百个共享的dll,其中许多还引用了其他dll,而这些dll本身也引用了其他dll,依此类推。 We have started to use a 'Shared' directory for all the dlls that we feel are generic enough to use in other projects, such as a database comms dll. 我们已经开始对所有我们认为足以在其他项目(例如数据库通信dll)中使用的dll使用“共享”目录。

The problem is that if one of the dlls all the way down the tree is changed, then everything that references it needs to be recompiled to avoid versioning issues (which occur at runtime). 问题在于,如果更改了整个树中的所有dll之一,则需要重新编译所有引用它的dll,以避免版本问题(在运行时发生)。

To avoid this, there is now talk of adding all our 'shared' dlls into one big assembly, and anyone creating new apps simply reference that, and that alone. 为避免这种情况,现在有人谈论将我们所有“共享”的dll添加到一个大程序集中,并且任何创建新应用的人都只是引用该引用,并且仅此引用。

This obviously will get bigger and bigger and i'm not sure if this is the best way or not. 这显然会越来越大,我不确定这是否是最好的方法。 Any thoughts please? 有什么想法吗?

What we do is treat the maintenance of the shared DLLs as a project in itself, with its own source-control and everything. 我们要做的是将共享DLL的维护本身视为一个项目,并带有其自己的源代码管理和所有内容。 Then about twice a year, we do a 'release' of the shared DLLs to the public, with its own version number and everything. 然后大约每年两次,我们使用自己的版本号和所有内容向公众“发布”共享的DLL。 As long as you always use the DLLs as a 'set' (meaning all the ones you reference are from the same release) you're guaranteed not to have any dependency issues. 只要您始终将DLL用作“集合”(意味着您引用的所有DLL都来自同一发行版),就可以保证不会有任何依赖性问题。

It's most definitely not the best way to do it. 绝对不是最好的方法。 I have a few "shared" DLLs at my job that are kind of like that. 我的工作中有一些类似的“共享” DLL。 They get unwieldy and difficult (read: impossible) to make meaningful changes to because it becomes too difficult to ensure that changes don't break apps downstream, which seems like the exact opposite of what you're trying to do. 由于难以确保更改不会破坏下游的应用程序,它们变得笨拙且难以(难以理解)进行有意义的更改,这似乎与您尝试做的事情完全相反。

It sounds like what you really need to do is separate your concerns a little bit better. 听起来您真正需要做的是将您的关注点更好地分离。 If all of these DLLs are referencing each other, they're probably too tightly coupled. 如果所有这些DLL相互引用,则它们可能耦合得太紧密。 A true "shared" DLL should be able to stand on its own, or as part of a packet of three or four that travel as a group. 真正的“共享” DLL应该能够独立存在,也可以作为一个整体传播的三到四个数据包的一部分。 If your dependencies are actually preventing you from making changes, then your coupling strategy has gone horribly wrong. 如果您的依赖关系实际上阻止了您进行更改,那么耦合策略就大错特错了。

Putting everything in one large DLL certainly isn't going to make anything better. 将所有内容放到一个大的DLL中肯定不会使任何事情变得更好。 In fact, probably the opposite. 实际上,可能恰恰相反。 Once you've got everything in one DLL, the temptation will be there to couple everything within it even more tightly together, which will make it impossible to pull things apart later. 一旦将所有内容都放在一个DLL中,就会有诱惑将其中的所有内容更紧密地耦合在一起,这将使以后无法将它们拆开。

you can make one solution that include all connected projects . 您可以制定一个包含所有关联项目的解决方案
and when you need to release, just build this solution 当您需要发布时,只需构建此解决方案


Update. 更新。
As you say, the solution is cant hold so much dlls. 正如您所说,解决方案无法容纳那么多dll。
In other hand you can make an external MSBuild script or using CruiseControl.NET that have possibilities to make such complicated tasks. 另一方面,您可以制作一个外部MSBuild脚本 使用CruiseControl.NET来执行这样的复杂任务。

To quote from the GoF book, "Program to an interface, not an implementation." 引用GoF的书中的“编程接口,而不是实现”。 This could apply here to some of your libraries. 这可能适用于您的某些库。 You are already aware of how brittle your develop becomes when you have tight coupling. 您已经意识到当紧密耦合时,开发会变得多么脆弱。 Now what needs to be addressed is how to give you breathing room. 现在需要解决的是如何为您提供呼吸空间。

  • You can create an interface. 您可以创建一个界面。 This will provide a contract that any application can use to specify that a minimum set of functionality is available. 这将提供任何应用程序都可以用来指定可用的最小功能集的合同。

  • You can create a Service that implements an interface. 您可以创建实现接口的服务。 This will allow you to provide what would be thought of as an addon or a plugin. 这将允许您提供被认为是插件或插件的东西。 This allows you to design towards a contract version with expectations that your tools will adhere to. 这使您可以朝着合同版本进行设计,并期望您的工具能够遵守。

  • You can create a Service that only uses an interface. 您可以创建仅使用接口的服务。 This will allow your application to send in any concrete implementation that adheres to a contract of design. 这将允许您的应用程序发送遵守设计合同的任何具体实现。

Products like development editors and web browsers use this approach to make some code reuse possible. 开发编辑器和Web浏览器之类的产品使用这种方法来使某些代码重用成为可能。 Thank you. 谢谢。 Good day. 美好的一天。

Design Principles from Design Patterns 设计模式中的设计原理

Plugin 插入

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

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