VS.NET:项目引用与程序集引用
关于从其他项目引用我们的公共代码库哪个更好:通过项目还是通过程序集,存在一些争论。我赞成引用该项目,特别是因为我们有自动化的单元测试,可以证明通用代码可以满足其需要。
另一个阵营的想法是锁定这些项目,每月只发布一次程序集或类似的东西。然后强制所有项目引用程序集。他们认为这将保护他们免于部署未经测试的代码。他们“太忙”了,无法编写自动化单元测试并配置他们的项目以进行持续集成,而我对此没有影响力,所以请不要关注这方面。
以下是我能想到的项目参考是更好解决方案的原因。我也在寻找其他意见。
优点:
- 引用项目可确保您使用最新的代码。您无需等待任何事情。
- 减少重复。如果没有最新的代码,则更有可能重新发明轮子。
- 如果开发人员需要某些东西,但无法将其添加到其所属的程序集中,那么它将在任何可用的位置创建它,从而造成许多不一致和代码重复。
- 开发变得更加容易,因为您可以轻松查看/调试引用代码中发生的情况。
- 我们常见的东西不会经常改变,但当改变时,它通常是有用的。为什么要增加维护和程序集发布管理的额外负担。
缺点:
- 加载可能需要更长的时间。
- 将项目添加到新解决方案然后添加程序集引用可能需要稍长的时间。
There's some debate here over which is better for referencing our common code base from other projects: by project or by assembly. I'm in favor of referencing the project, especially since we have automated unit tests that prove that the common code does what it needs to.
The thought from the other camp is to lock down those projects and only release assemblies once a month or something. Then force all projects to reference the assemblies. They think this will protect them from deploying untested code. They are "too busy" to write automated unit tests and configure their projects for continuous integration and I have no influence on that, so please do not focus on this aspect.
Here's the reasons I can think of why project references are the better solution. I'm looking for other opinions as well.
PROS:
- Referencing projects ensures you are working with the latest code. You don't have to wait on anything.
- Reducing duplication. Without having the latest code, there is a greater chance of reinventing the wheel.
- If a developer needs something and can't add it to the assembly where it belongs, it will be created in any location that will work, creating many inconsistencies and code duplication.
- Development is easier because you can easily see/debug what is happening in the referenced code.
- Our common stuff doesn't change that often, but when it does, it's usually something useful. Why add the extra burden of maintenance and assembly release management.
CONS:
- Could possibly take longer to load.
- Can take slightly longer to add projects to a new solution then adding assembly references.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是您错过的实时更新的一些优点
针对您的缺点
Here are a couple of pros you missed
In response to your cons
好吧,如果您使用任何类型的源代码控制,您就可以满足两个阵营。使用分支或标签(取决于您的源代码管理)。
基本上,如果您有一个团队控制您的通用代码,他们可以分支/标记稳定版本。然后您的项目将使用稳定版本。这可以防止您为其他项目部署不稳定的代码,同时为您提供测试、调试和查看所有源代码的能力。
每当您的公共控制团队创建新的稳定版本时,您都可以更新源引用以从新分支中提取。
这种情况的另一个好处是您可以对通用代码进行补丁,以免扰乱当前正在进行的开发工作。当然,这确实增加了额外的管理负担,需要在多个地方更新公共代码。
Well, if you are using any type of source control you could satisfy both camps. Using Branching or Labeling (depending on your source control).
Basically if you have a team that is in control of your common code they can branch / label a stable release. Then your projects would use the stable release. This protects you from deploying unstable code for your other projects while providing you the ability to test, debug, and view all the source.
Whenever your common controls team creates a new stable build you can update your source references to pull from the new branch.
The other up side to this scenario is you could have a patch on the common code so as not to mess with the current ongoing development efforts. Of course this does add an extra management burden of updating the common code in more than one place where necessary.
引用策略将始终是一个常见问题
我知道这是一个非常古老的问题,但它始终是一个具有相关答案的相关问题,我记得几年前也遇到过同样的问题以及该问题的影响两种选择(项目与程序集参考)只是在过去两年里我才变得明显起来,当时我正在全职开发一个系统的构建器,该系统包含 800 多个项目,单个 WPF 应用程序有 300 多个解决方案。
项目引用对于 VISUAL STUDIO 来说是理想的
项目引用是理想的,因为您可以让 IDE 更深入地了解代码的详细信息,因为您明确告诉 Visual Studio 引用的项目及其所有代码的位置。如果您正在使用的系统少于 200 个项目模块,并且只能拥有几个解决方案(项目分组),请查找项目参考,因为 Visual Studio 可以在设计时使用这些额外信息为您做更多事情,例如向您展示代码而不是反映引用的程序集。
汇编引用可以更好地扩展
如果您的系统远大于 200 个项目,您的构建可能会变得非常慢。我见过每个构建 20 分钟,这真的很糟糕。因此,如果您可以引用一个不会更改的 DLL,那么您就是在告诉 Visual Studio“不”构建它,这显然会对构建时间产生一些影响。
汇编引用创建了一个解耦系统的幻象
项目引用为您提供了一个更智能的 IDE,它始终知道在何处以及在多少位置使用了类型、可以在哪里找到代码以及其他一些有用的统计信息,因为所有项目都直接引用。当您无意中尝试创建循环引用时,它还会向您发出警告。
程序集引用的优点:
程序集引用的缺点:
循环引用成为可能,经验不足的开发人员最初不会注意到这些引用。
<块引用>
您可以通过将其中一个程序集视为已签入的第三方程序集、将其转移到下一个版本并最后构建它来解决循环引用的这一挑战。当使用此排除程序集的项目上的构建失败时,您可以决定重建该指定项目,并且通常会消除循环依赖关系。 (不推荐,但有可能)
循环引用
<块引用>
新项目默认使用最新版本的 .net 框架,没有考虑到当前解决方案中的所有项目仍处于早期版本的 .net 中这一事实,因此当您使用程序集引用添加对该项目的引用时,您经常会遇到一个不太容易弄清楚的奇怪错误。
<块引用>
您单击“添加引用”,向上移动几个目录,向下移动几个目录,选择 dll 并单击添加,但没有意识到该 dll 实际上与您正在处理的另一个分支中的位置太远了。只有当构建服务器尝试解析该程序集并失败时,这个问题才会变得明显。以及错误“未知的命名空间,您是否缺少程序集引用?”根本不会帮助你浪费整个团队的时间。
REFERENCING STRATEGY WILL ALWAYS BE A COMMON PROBLEM
I know this is a very old question but it will always be a relevant question with relative answers and I remember having this same question a few years ago and the impact of the two choices (project versus assembly references) only became apparent to me during the last two years while I was working full time on a builder for a system with 800+ projects in 300+ solutions for a single WPF app.
PROJECT REFERENCES ARE IDEAL FOR VISUAL STUDIO
Project references are ideal because you give the IDE much more insight into the details of your code because you are explicitly telling Visual Studio where the referenced project and all of its code is. If you are working on a system with less than 200 project modules and can afford to have only a few solutions (project groupings), go for project references because Visual Studio can do more for you with that extra information during design-time like showing you the code instead of reflecting referenced assemblies.
ASSEMBLY REFERENCES CAN SCALE BETTER
If your system is much larger than 200 projects, your builds may become very slow. I've seen 20 minutes per build and that really sucks. So if you can reference a DLL that doesn't change, you are telling Visual Studio "NOT" to build it, and that obviously has some impact on the time to build.
ASSEMBLY REFERENCES CREATE AN ILLUSION OF A DECOUPLED SYSTEM
Project references offer you a smarter IDE that always knows where and in how many places a type is used, where the code can be found, and some other useful statistics because all the projects are referenced directly. It can also warn you when you inadvertently tried to create a circular reference.
PROS of assembly references:
DISADVANTAGES of assembly references:
Circular references become possible, and your less experienced developers won't notice those references initially.