MSBuild-它可以解决解决方案文件中的项目依赖性吗?如果可以,怎么办? [英] MSBuild - can it work out project dependencies in a solution file? If so how?

查看:83
本文介绍了MSBuild-它可以解决解决方案文件中的项目依赖性吗?如果可以,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个msbuild项目,该项目从Visual Studio构建一个SLN文件,该文件将所有项目保存在其中(约70多个项目),并且许多项目相互依赖,这意味着它们需要按顺序构建-有时开发人员忘记了在Visual Studio中的解决方案文件中手动设置构建顺序,这会导致干净的解决方案上的msbuild失败,因为某些构建问题/无法找到dll.

msbuild是否有办法采用所有项目并计算依赖关系并按顺序构建项目,如果有的话我该怎么做?使用MSBuild任务?在当前尝试下,如果我传入项目文件和路径的列表,似乎只是按照读取项目的顺序进行构建.

目前,我能想到的唯一解决方法是使用外部应用程序,该应用程序扫描proj文件和引用,然后每次手动创建解决方案.

有人解决过/见过吗?

解决方案

尽管项目依赖关系难以维护且无法在.sln文件之间共享,但是尊重项目参考并确实规定了顺序-请参阅Microsoft.Common.targets中的ResolveReferences任务.

旁听:我的一个朋友"可能在重构期间"意外地将其构建Task存根,并且将它与Microsoft.Common.targets ResolveReferences任务关联为DependsOnTargets,最终导致未获得ProjectReferences以听起来像这里的问题的方式获得荣誉.如果您请阅读一些帖子,您可能会觉得这简直太疯狂了-并非如此;摇摇欲坠的是项目依赖项,而不是项目引用.


请参见 Dan Moseley撰写的这篇出色的MSDN Blog文章确实解释了该主题,包括一些有用的解决方法. (通过与构建xUnit.net的此轻微相关的问题).

I have an msbuild project which builds a SLN file from visual studio which holds all the projects in (about 70+ project), and a lot of the projects are dependent on each other meaning they need to be build in order - sometimes a developer forgets to set the build order manually in visual studio in the solution file causing the msbuild on a clean solution to fail as something gets built out of order/cant find a dll.

Is there a way for msbuild to take all projects and work out the dependencies and build the projects in order, if there is how do i do this? using an MSBuild task? With current tries it seems to just build in the order it reads the projects in - if i pass in a list of project files+paths.

Currently the only way i can think to solve this is a external app which scans the proj files and references and then manually creates a solution each time.. but this seems overkill for such a simple thing.

Anyone solved / seen this before?

解决方案

While Project Dependencies are hard to maintain and not shared across .sln files, Project References are honoured and do dictate the order consistently - see the ResolveReferences task in Microsoft.Common.targets.

ASIDE: A 'friend of mine' may 'during a refactoring' have accidentally stubbed out their Build Task and it's DependsOnTargets linkage to the Microsoft.Common.targets ResolveReferences task and ended up with ProjectReferences not being honoured in ways that sound like the question here. If you read some of the posts, you might get the idea that it's all mad shaky - it's not; the shaky bits are the Project dependencies, not the Project references.


See this excellent MSDN Blog article by Dan Moseley that really explains the topic, including some useful workaround strategies. (via this mildly related issue with building xUnit.net).

这篇关于MSBuild-它可以解决解决方案文件中的项目依赖性吗?如果可以,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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