最终编译的程序集中.Net 中的项目和 dll 依赖关系之间的差异
假设我有两个项目 A 和 B。A 依赖于 B。我可以通过两种方式指定这一点:
- 将 A 和 B 包含在同一解决方案中,并将 B 指定为 A 的项目依赖项。这在 A 的 msbuild 项目中显示为“项目参考”节点。
- 包括对 B 编译的 dll 的引用作为 A 的依赖项。这在 A 的 msbuild 项目中显示为“参考”节点
我的问题是,一旦我为 A 构建了程序集,这些之间的最终输出是否存在差异两种方法。
我尝试创建几个简单的项目来模拟这种关系并尝试进行比较 - 但不同的比较工具告诉我不同的事情。在写一些逐字节比较这些文件的内容之前,我想知道你们是否对此有所了解。具体来说,如果我使用 dll 引用而不是项目引用,构建的程序集的行为是否会有任何差异。
Lets say I have two projects A and B. A depends on B. I can specify this in two ways:
- Include A and B in the same solution and specify B as a project dependency for A. This shows up in A's msbuild project as a "ProjectReference" node.
- Include a reference to the B's compiled dll as dependency for A. This shows up in A's msbuild project as a "Reference" node
My question is, once I've build the assembly for A, is there a difference in the final output between these two methods.
I tried creating a couple of simple projects which model this relation and tried a comparison - but different comparison tools are telling me different things. Pending writing something which compares these files byte-by-byte, I was wondering if you folks knew anything about this. Specifically, will there be any difference in the behaviour of the built assembly if I use dll reference instead of a project reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果项目 B 源在项目 A 的两次构建之间没有更改,则项目 A 输出的行为不会有任何差异。但是,如果项目 B 源已更改,将其作为项目 A 中的项目引用将导致项目 B 也被重建。这种差异决定了您选择如何从项目 A 引用项目 B:
如果您拥有项目 B 和项目 A 的源代码,并且它们紧密耦合,或者它们都在积极开发中并且项目 B其公共接口经常发生重大变化,您希望将项目 B 引用为项目。这将确保项目 A 始终在其构建中使用项目 B 的最新输出。
如果项目 B 是外部依赖项,则您不会自己开发,或者您没有源代码,或者如果它已经发布并且您无法与项目 A 一起发布修改版本,则您需要引用预构建的项目 B 输出,以确保您正在使用项目 B 的相同版本进行开发和测试,这很可能在用户的计算机上。
If the project B sources have not changed in between two builds of project A, there will be no difference in the behavior of the project A output. However, if project B sources have changed, referencing it as a project from project A will cause project B to be rebuilt as well. This difference is what determines your choice of how to reference project B from project A:
if you own the source of both project B and project A, and they are tightly coupled, or if they both are under active development and project B undergoes often breaking changes of its public interface, you want to reference project B as project. This would ensure that project A always uses in its build the most up-to-date output of project B.
if project B is external dependency you don't develop yourself, or you don't have the sources to, or if it has been shipped already and you can't ship modified version with project A, you want to reference the pre-built project B output, to ensure you are developing and testing with the same version of project B, that is most likely to be on your users' computers.
添加为项目引用的优点是,如果需要,可以自动构建程序集“B”。
一旦构建了组件“A”,就没有区别了。
Adding as project reference just has the advantage that assembly "B" is automatically built if required.
Once assembly "A" is built, there is no difference.