问题描述
在将解决方案拆分为逻辑层时,何时最好使用单独的项目而不是仅按文件夹分组?
推荐答案
默认情况下,总是在同一个项目中创建新文件夹
- 您将获得单个组件(无需额外的 ILMerge 体操)
- 更容易混淆(因为您将拥有更少的公共类型和方法,最好完全没有)
将源代码分成多个项目只有在您...时才有意义
- 有一些源代码部分是项目的一部分,但默认情况下或根本不可部署(单元测试、额外插件等)
- 涉及更多开发人员,您希望将他们的工作视为可消耗的黑匣子.(不太推荐)
- 如果您可以清楚地将您的项目分成独立的层/模块,并且您想确保它们不能交叉使用 internal 成员.(也不推荐,因为您需要决定哪个方面最重要)
如果您认为源代码的某些部分可以重复使用,请不要将其创建为新项目.等到您真的想在另一个解决方案中重用它并根据需要将其从原始项目中隔离出来.编程不是乐高积木,重用通常非常困难,而且通常不会按计划进行.
问题描述
When spliting a solution in to logical layers, when is it best to use a separate project over just grouping by a folder?
推荐答案
By default, always just create new folder within the same project
- You will get single assembly (without additional ILMerge gymnastic)
- Easier to obfuscate (because you will have less public types and methods, ideally none at all)
Separating your source code into multiple projects makes only sense if you...
- Have some portions of the source code that are part of the project but not deployable by default or at all (unit tests, extra plugins etc.)
- More developers involved and you want to treat their work as consumable black box. (not very recommended)
- If you can clearly separate your project into isolated layers/modules and you want to make sure that they can't cross-consume internal members. (also not recommended because you will need to decide which aspect is the most important)
If you think that some portions of your source code could be reusable, still don't create it as a new project. Just wait until you will really want to reuse it in another solution and isolate it out of original project as needed. Programming is not a lego, reusing is usually very difficult and often won't happen as planned.