自定义构建步骤和构建后事件有什么区别?

发布于 2024-09-26 04:23:31 字数 38 浏览 9 评论 0原文

这两个项目设置都允许我执行自定义命令。各自的优点或缺点是什么?

Both project settings allow me to execute custom commands. What are the benefits or drawbacks of each?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守护在此方 2024-10-03 04:23:31

差别很大。自定义构建步骤允许您指定依赖项和输出。这允许构建系统确定何时执行该步骤,并在输出已经是最新时跳过它。当项目需要构建并且其时间固定时,构建后事件总是执行。

Big difference. A custom build step allows you to specify dependencies and outputs. Which allows the build system to determine when to execute the step and to skip it when the output is already up to date. A post-build event is always executed when the project requires building and its timing is fixed.

稍尽春風 2024-10-03 04:23:31

似乎@Hans 答案已经切换了,主要区别在于,如果不需要构建文件,则不会发生构建事件。


来自 msdn 文档:

生成事件和自定义生成步骤与其他生成步骤一起按以下顺序运行:

Pre-Build event
Custom build tools on individual files
MIDL
Resource compiler
The C/C++ compiler
Pre-Link event
Linker or Librarian (as appropriate)
Manifest Tool
BSCMake
Custom build step on the project
Post-Build event

项目上的自定义生成步骤和生成后事件在所有其他生成过程完成后按顺序运行。

仅当构建成功到达构建过程中的这些点时才会执行构建事件。如果构建中发生错误,则不会发生构建后事件;如果错误发生在链接阶段之前,则预链接事件和构建后事件都不会发生。此外,如果不需要链接文件,则不会发生预链接事件。预链接事件在不包含链接步骤的项目中也不可用。
如果不需要生成文件,则不会发生生成事件。

在 Visual Studio C++ 开发环境中,可以使用三种基本方法来自定义生成过程:

自定义生成步骤 >
自定义构建步骤是与项目关联的构建规则。自定义构建步骤可以指定要执行的命令行、任何其他输入或输出文件以及要显示的消息。有关详细信息,请参阅如何:向 MSBuild 项目添加自定义生成步骤。

自定义构建工具
自定义构建工具是与一个或多个文件关联的构建规则。自定义构建步骤可以将输入文件传递给自定义构建工具,从而生成一个或多个输出文件。例如,MFC 应用程序中的帮助文件是使用自定义构建工具构建的。有关详细信息,请参阅如何:将自定义生成工具添加到 MSBuild 项目和指定自定义生成工具。
构建事件

构建事件让您可以自定义项目的构建。共有三个构建事件:预构建、预链接和后构建。构建事件允许您指定在构建过程中的特定时间发生的操作。例如,您可以在项目完成构建后使用构建事件向 regsvr32.exe 注册文件。有关详细信息,请参阅指定构建事件。

seems @Hans answer got it switched, main difference is that if no files need to be built, no build events will occur.


from the msdn documentation:

Build events and custom build steps run in the following order along with other build steps:

Pre-Build event
Custom build tools on individual files
MIDL
Resource compiler
The C/C++ compiler
Pre-Link event
Linker or Librarian (as appropriate)
Manifest Tool
BSCMake
Custom build step on the project
Post-Build event

The custom build step on the project and a post-build event run sequentially after all other build processes finish.

Build events are executed only if the build successfully reaches those points in the build process. If an error occurs in the build, the post-build event will not occur; if the error occurs before the linking phase, neither the pre-link nor the post-build event will occur. Additionally, if no files need to be linked, the pre-link event will not occur. The pre-link event is also not available in projects that do not contain a link step.
If no files need to be built, no build events will occur.

From within the Visual Studio C++ development environment, there are three basic ways to customize the build process:

Custom Build Steps
A custom build step is a build rule associated with a project. A custom build step can specify a command line to execute, any additional input or output files, and a message to display. For more information, see How to: Add a Custom Build Step to MSBuild Projects.

Custom Build Tools
A custom build tool is a build rule associated with one or more files. A custom build step can pass input files to a custom build tool, which results in one or more output files. For example, the help files in an MFC application are built with a custom build tool. For more information, see How to: Add Custom Build Tools to MSBuild Projects and Specifying Custom Build Tools.
Build Events

Build events let you customize a project's build. There are three build events: pre-build, pre-link, and post-build. A build event lets you specify an action to occur at a specific time in the build process. For example, you could use a build event to register a file with regsvr32.exe after the project finishes building. For more information, see Specifying Build Events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文