[英]How to compile another project before compiling main project?
I have a solution with two executing projects.我有一个包含两个执行项目的解决方案。 Users can execute project B from project A by pressing a button.
用户可以通过按一个按钮从项目 A 执行项目 B。 Project A Debug folder contains the project B Debug folder, so it executes project B by the hardcoded path to that folder.
项目 A Debug 文件夹包含项目 B Debug 文件夹,因此它通过该文件夹的硬编码路径执行项目 B。 If I want to make some changes in project B - I need to recompile project B and replace its Debug folder in project A Debug folder.
如果我想在项目 B 中进行一些更改 - 我需要重新编译项目 B 并在项目 A 的 Debug 文件夹中替换它的 Debug 文件夹。 I think it's not a smart and comfortable way from the point of architecture view.
我认为从架构的角度来看,这不是一种聪明而舒适的方式。 So I want to include such actions in project A build events, but I have never done it before, so I would be happy to hear your suggestions.
所以我想在项目 A 构建事件中包含这样的操作,但我以前从未这样做过,所以我很高兴听到你的建议。
The easiest way to achieve this is to create a reference from A to B, so you coud access the (public) members of B from project A. This way, you could also run the code of B in the process of A, eliminating the need to start a separate process.最简单的实现方式是创建一个从A到B的引用,这样你就可以从项目A访问B的(公共)成员。这样,你也可以在A的过程中运行B的代码,消除了需要启动一个单独的进程。
If you do have the requirement that you need to have a separate exe for B that runs in a separate process, there is another approach that requires more effort:如果您确实需要为在单独进程中运行的 B 提供单独的 exe,则还有另一种方法需要更多努力:
<Target Name="AfterBuild">
<ItemGroup>
<AdditionalFiles Include="$(MSBuildProjectDirectory)\..\ProjectB\bin\$(Configuration)\ProjectB.*" />
</ItemGroup>
<Copy SourceFiles="@(AdditionalFiles)" DestinationFolder="$(OutputPath)" />
</Target>
<Target Name="AfterClean">
<ItemGroup>
<AdditionalFilesToDelete Include="$(OutputPath)\ProjectB.*" />
</ItemGroup>
<Delete Files="@(AdditionalFilesToDelete)" />
</Target>
Please see the documentation on build targets and note that the code above is only a sample that you need to adjust to your specific needs.请参阅有关构建目标的文档,并注意上面的代码只是您需要根据特定需求进行调整的示例。 For instance, it only works with the standard output paths.
例如,它仅适用于标准输出路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.