简体   繁体   English

生成C#项目及其依赖项

[英]Build C# Projects and their dependencies

In VS2005 I have a few C# projects that depend on each other. 在VS2005中,我有一些相互依赖的C#项目。

If project A depends on B (eg references it), then I want B to build whenever I build A, assuming B has changed in some way since last built. 如果项目A依赖于B(例如引用它),那么我希望B在每次构建A时都进行构建,假设B自上次构建以来已经发生了某些变化。 That's the way it is with VC projects, but for some reason it doesn't seem to work with C# projects. VC项目就是这样,但是由于某些原因,它似乎不适用于C#项目。 If I clean B and then build A it just tells me that it can't find B... 如果我先清理B再构建A,它只会告诉我找不到B ...

Any ideas? 有任何想法吗?

If you right-click on your Visual Studio Solution and choose "Project Build Order" you can verify the order in which those individual projects are being built. 如果右键单击Visual Studio解决方案,然后选择“项目构建顺序”,则可以验证构建各个项目的顺序。 ALSO make sure that you aren't referencing a "debug" DLL in a "release" build and vice versa. 还请确保您没有在“发行”版本中引用“调试” DLL,反之亦然。

您需要构建实际的解决方案,而不是单独构建项目。

A Solution lets you define Dependencies between Projects. 解决方案使您可以定义项目之间的依赖关系。 And if you use that, it should work automatically. 而且,如果您使用它,它将自动运行。 Normally the dependencies are set up automatic too. 通常,依赖项也自动设置。 Chances are you added a reference to the assembly, not the project. 您可能会添加对程序集的引用,而不是项目的引用。 Watch the Projects tab in the Add reference dialog. 观看“添加引用”对话框中的“项目”标签。

If you add all the projects to the same solution and set up the dependencies between them then Visual Studio should be able to work out the correct order and build everything that needs building when you change something in one of the "lower" projects. 如果将所有项目添加到同一解决方案中并设置它们之间的依赖项,则当您在“较低”项目之一中进行更改时,Visual Studio应该能够确定正确的顺序并构建需要构建的所有内容。

In your case it would know that it had to rebuild B before building A. 在您的情况下,它将知道必须在构建A之前重新构建B。

override the target AfterResolveReferences in your csproj. 覆盖csproj中的目标AfterResolveReferences。 Then use the item @(NonVCProjectReference) to list the path to every project and build them. 然后使用项目@(NonVCProjectReference)列出每个项目的路径并进行构建。 I recommend you to read the MSBuild documentation 我建议您阅读MSBuild文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM