通过DLL参考,而不是由VS项目引用管理.NET程序集的依赖性 [英] Managing .NET assembly dependencies by dll reference rather than by project reference in VS

查看:438
本文介绍了通过DLL参考,而不是由VS项目引用管理.NET程序集的依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个.NET项目由多个子项目(约20)。有几种解决方案,每个包含只有那些子项目相关的特定解决方案。

We have a .NET project consisting of multiple subprojects (around 20). There are several solutions, each containing only those subprojects which are relevant to the particular solution.

要允许任意的解决方案,我们的子项目从未相互引用由项目引用的方式,而是通过直接的dll引用。还有就是的csproj文件的小调整,使HintPath包括$(配置),因此调试版本调试引用的DLL和发布版本的参考版本的DLL。

To allow for arbitrary solutions, our subprojects never reference each other by means of project references, but rather by direct dll references. There is little tweaking of the csproj file, to make HintPath include $(Configuration), so Debug builds reference Debug dlls and Release builds reference Release dlls.

所有的伟大工程,但有两个主要问题 - 一个是恼人的,另一种是真的急:

All works great, but there are two major problems - one is annoying and another is really acute:

  1. VS没有认识到依赖计算的目的DLL引用。我们必须手工指定一个新的项目或引用添加每次使用项目依赖对话框中的相关性。这是烦人。
  2. 我们既不使用ReSharper的,也不视觉辅助系统(伟大的工具,但我们不使用它们,这是一个给定的)。我们不喜欢用标准的浏览定义命令(可从源头code中的上下文菜单,例如)。急性问题是,它只能跨项目,如果一个项目使用项目引用引用其他的,它不工作时,引用是直接的dll引用,即使引用的项目包含在解决方案!这是因为,而不是导航到导航元数据源真正的无赖。
  1. VS does not recognize dll references for the purpose of the dependency calculation. We have to manually specify the dependencies using the "Project Dependencies" dialog each time a new project or reference is added. This is annoying.
  2. We use neither Resharper nor Visual Assist (great tools, but we do not use them, it's a given). We do like to use the standard "Browse to Definition" command (available from the context menu on the source code, for instance). The acute problem is that it only works cross project if one project references the other using the project reference and it does not work when the reference is the direct dll reference, even if the referenced project is included in the solution! That's a real bummer, because instead of navigating to the source it navigates to the metadata.

我是要求这些人在那里谁使用的DLL参考像我们,在一定程度上将解决这两个问题的建议。 谢谢你。

I am seeking for an advice of those folks out there who use dll references like us and have somehow overcome these two issues. Thanks.

编辑:

请注意,这除了浏览定义的问题,有DLL引用,而不是项目引用招致对项目经理只有一个时间成本 - 这是当一个新的项目加入到更新每个受影响的解决方案的项目依赖关系或一个新的依赖关系必须被引入。这些项目依赖持久保存在.sln文件,并且不需要任何维护,直到一个新的项目到达或创建一个新的依赖,这恰好不是过于频繁。

Note, that besides the "Browse to Definition" issue, having Dll references instead of project references incurs only one time cost on the project manager - which is to update the project dependencies of each affected solution when a new project is added or a new dependency must be introduced. These project dependencies are persisted in the .sln file and do not require any maintenance until a new project arrives or a new dependency is created, which happens not that too often.

我们正在使用的MSBuild的CI服务器,它使用相同的.sln文件作为VS不上建立我们的项目。有一个主要的.sln文件,其中包括所有的子项目。

We are using msbuild for building our projects on the CI server, which uses the same .sln files as VS does. There is one main .sln file, which includes all the subprojects.

我要强调的更尖锐的问题 - 无法浏览到另一个项目确定指标,虽然这两个项目都在同一个解决方案,只是因为引用dll的引用。这是恼人的,它是一个麻烦事,没有理由VS坚持项目引用启用该功能。其他工具,如ReSharper的或视觉辅助系统没有此限制。唉,我们没有这些工具,并不太可能在可观察到的未来。

I wish to emphasize the more acute problem - the inability to browse to a defintion in another project, although both projects are in the same solution just because the references are dll references. This is annoying and it is a nuisance, there is no reason why VS insists on project references to enable the feature. Other tools, like Resharper or Visual Assist do not have this limitation. Alas, we do not have these tools and unlikely to have in the observable future.

推荐答案

您的构建配置的问题如下:说你有3个项目和2个解决方案

The problem with your build configuration is the following: say you have 3 projects and 2 solutions.

Solution1
- Project1
- Project2
Solution2
- Project1
- Project3

突然,建筑溶液2建立的的部分的的code的解决方法1,使其处于无效状态(最新版本是要么不兼容或不需要待建)。

All of a sudden, building Solution2 builds part of the code for Solution1, leaving it in an invalid state (the latest binaries are either incompatible or did not need to be built).

每个项目都应该包含在一个单一的解决方案。其它解决方案可以依靠,但不应该积极转变这些项目的code。通过这种方式,他们可以参考内置DLL,因为没有任何理由来重建外部依赖。

Every project should be included in a single solution. Other solutions can rely on, but should not actively change the code of those projects. In this way, they can reference a built DLL because there's no reason to rebuild the external dependencies.

要总结,你应该花一些时间和调整你的解决方案,以满足以下条件:

To summarize, you should take some time and restructure your solutions to meet the following conditions:

  • 在每个项目都包括在只有一个解决方案。
  • 如果一个项目依赖于同一个解决方案中的另一个项目,使之成为项目的参考。
  • 如果一个项目依赖于一个的不同的的解决方案的另一个项目,使其成为一个DLL的参考。
  • Every project is included in exactly one solution.
  • If a project depends on another project within the same solution, make it a project reference.
  • If a project depends on another project in a different solution, make it a DLL reference.

在除了上述,我建议用于放置创建一个外部对象目录建立时它们是由其他的解决方案中引用。说你调整为以下内容:

In addition to the above, I recommend creating an "Externals" directory for placing builds in when they are referenced by other solutions. Say you restructure to the following:

Solution1
- Project1
- Project2 -> reference project Project1
Solution2
- Project3 -> reference Project1.dll

在这种情况下,你会放置Project1.dll和Project1.pdb的副本外部对象\ PROJECT1 \调试外部对象\ PROJECT1 \发布,并参照外部\ PROJECT1 \ $(配置)\ Project1.dll 的项目3。仅更新建立在外部材料的目录,当你准备好构建推送到你所有的其他的解决方案。

In this case, you'd place copies of Project1.dll and Project1.pdb in Externals\Project1\Debug and Externals\Project1\Release, and reference External\Project1\$(Configuration)\Project1.dll in Project3. Only update the builds in the Externals directory when you are ready to push the build to all your other solutions.

这篇关于通过DLL参考,而不是由VS项目引用管理.NET程序集的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆