简体   繁体   English

用于生成标头的 Visual Studio 自定义构建步骤

[英]visual studio custom build step to generate headers

I have a project with headers that is normally generate as needed with command line interface.我有一个带有标题的项目,通常根据需要使用命令行界面生成。 But i want to add this generation step to visual studio 2015 (toolset v141, c++) as a custom build step.但我想将此生成步骤添加到 Visual Studio 2015(工具集 v141,c++)作为自定义构建步骤。 So i did it and it actually works but it generates them to late.所以我做到了,它确实有效,但它生成它们很晚。 Indeed, if the files do not existe yet, it fails building the project with error "cannot include file myHeader.h".实际上,如果文件尚不存在,则无法构建项目并出现错误“无法包含文件 myHeader.h”。

i added the custom build step by adding project properties -> Custom Build Step -> general:我通过添加项目属性 -> 自定义构建步骤 -> 常规添加了自定义构建步骤:

  • Command line: the command to generate header file (it works)命令行:生成header文件的命令(有效)
  • Outputs: $(ProjectDir)generated-header;%(Outputs)输出: $(ProjectDir)生成的标题;%(输出)
  • Execute Before: PreBuildEvent之前执行: PreBuildEvent

Ouputs is actually not needed as the command line generates the files and automatically place them in the rigth folder.实际上不需要输出,因为命令行会生成文件并自动将它们放在 rigth 文件夹中。 but it does not work if i do not specify an output folder.但如果我不指定 output 文件夹,它将不起作用。

Execute Before might be where my probleme is.执行之前可能是我的问题所在。 But i don't know which option to add.但我不知道要添加哪个选项。 this one seems good yet.这个似乎还不错。

EDIT something weird is that it sometimes succeed to create it before the build but if i delete them and build again.编辑有些奇怪的是,它有时会在构建之前成功创建它,但如果我删除它们并再次构建。 They are not generated anymore and the project does not build.它们不再生成,项目也不会构建。

EDIT2 actually it works only if i modify the project properties as it forces to regenerate all the requirements. EDIT2实际上只有在我修改项目属性时才有效,因为它强制重新生成所有需求。 Otherwise, if i build as usual, it skip the custom buld step because visual studio think that it is up to date.否则,如果我像往常一样构建,它会跳过自定义 buld 步骤,因为 Visual Studio 认为它是最新的。

It seems that i solved it.看来我解决了。 I made a custom build step to generate my files but it is said here我做了一个自定义构建步骤来生成我的文件,但这里

Custom Buil Step自定义构建步骤

Custom Build Steps are included as part of the intelligence that drives incremental build using the “Additional Dependencies” and “Outputs” properties.自定义构建步骤包含在使用“附加依赖项”和“输出”属性驱动增量构建的智能中。 If a file in your “Additional Dependencies” property is touched, then your Custom Build Step will be considered out of date and will build with your next build如果触及“附加依赖项”属性中的文件,则您的自定义构建步骤将被视为已过期,并将与您的下一个构建一起构建

Build Events构建事件

Nothing much changed here since VS2008.自 VS2008 以来,这里没有太大变化。 These three events (Pre-build, Pre-link, and Post-build) fire during the course of a normal build and allow you to execute arbitrary project-level commands.这三个事件(预构建、预链接和构建后)在正常构建过程中触发,并允许您执行任意项目级命令。

I thus create a Build event and my files are now generated any time and before checking for include files.因此,我创建了一个 Build 事件,现在我的文件在检查包含文件之前随时生成。

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

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