I am developping a DSL with its own graphical editor. Such files have a .own extension. I also have a small tool that compiles .own files into .h files.
我正在使用自己的图形编辑器开发DSL。此类文件具有.own扩展名。我还有一个小工具,可以将.own文件编译成.h文件。
X.own --> X.h and X/*.h
X.own - > X.h和X / *。h
I have written a simple .rules file to launch the generation.
我写了一个简单的.rules文件来启动这一代。
My problem is the following : Most of my source files include X.h, but a change in X.own does not mean the generated X.h (or any other generated file) will be different. This is dealt with by the generator through the use of temporary files and file comparison. But Visual Studio does not seem to know how to deal with all this. If i set the "output file(s)" property to the right file(s), it always assumes they will be changed. If i don't, it generates its build process assuming they won't be !
我的问题如下:我的大多数源文件都包含X.h,但X.own中的更改并不意味着生成的X.h(或任何其他生成的文件)将不同。这是由生成器通过使用临时文件和文件比较来处理的。但Visual Studio似乎并不知道如何处理这一切。如果我将“输出文件”属性设置为正确的文件,它始终假定它们将被更改。如果我不这样做,它会生成它的构建过程,假设它们不会!
How can i make things right ?
我怎样才能把事情做对?
1) Launch custom build tool
1)启动自定义构建工具
2) Compute build process based on dependencies
2)基于依赖性计算构建过程
2 个解决方案
#1
Don't use the custom build tool options but instead set it up as a pre-build event for the solution (this can take a general command line, just like the custom build tool). This way MSVS will not examine the generated files. As long as they are #included or listed in the solution explorer they should be compiled fine as the generation of the .h files will happen before any other compilation.
不要使用自定义构建工具选项,而是将其设置为解决方案的预构建事件(这可以采用通用命令行,就像自定义构建工具一样)。这样MSVS就不会检查生成的文件。只要它们是#included或列在解决方案资源管理器中,它们就应该被编译好,因为.h文件的生成将在任何其他编译之前发生。
I find the custom build tool is not so useful as the pre- and post- build events in general, because of the way it expects files to be generated or modified. You might find this tool useful for other things in the future (e.g. to compress the .exe after build, to generate other dependencies correctly, to ensure files are in place etc...)
我发现自定义构建工具通常不像构建前和构建后事件那么有用,因为它期望生成或修改文件的方式。您可能会发现此工具在将来对其他事情有用(例如,在构建后压缩.exe,正确生成其他依赖项,以确保文件到位等等)
There is a nice diagram showing where to find these options in the solution properties here
这里有一个很好的图表,显示在解决方案属性中找到这些选项的位置
#2
jheriko's answer is interesting, because it provides a way to launch custom tool, then generate build dependencies. But it's not very usable, because you then lose all possibilities to use "custom build tools" toolkit, in which you can
jheriko的回答很有意思,因为它提供了一种启动自定义工具的方法,然后生成构建依赖项。但它不是很有用,因为你失去了使用“自定义构建工具”工具包的所有可能性,你可以在其中使用
- choose to always compile files with some precise extension
- manually skip custom build for a particular file in a particular project configuration (and visualize this decision)
选择始终使用一些精确的扩展名编译文件
手动跳过特定项目配置中特定文件的自定义构建(并可视化此决策)
There is no way (or at least i have found none) to "have it all". The only way i have found is to have the custom build tool return a non-zero number when files have been updated, with a message to the user explaining that it is not an error and inviting him to launch build again. The next time, custom build tool is launched again (not optimal, but the tool i use is pretty fast) but modifies no new file, and build process goes on, using valid dependencies.
没有办法(或者至少我没有发现任何东西)“拥有一切”。我找到的唯一方法是让文件更新时自定义构建工具返回非零数字,并向用户发送一条消息,说明这不是错误并邀请他再次启动构建。下一次,自定义构建工具再次启动(不是最佳的,但我使用的工具非常快)但不修改新文件,并使用有效的依赖项继续构建过程。
Note : the approach described above does not work with Incredibuild, which seems to ignore project build order.
注意:上述方法不适用于Incredibuild,它似乎忽略了项目构建顺序。
#1
Don't use the custom build tool options but instead set it up as a pre-build event for the solution (this can take a general command line, just like the custom build tool). This way MSVS will not examine the generated files. As long as they are #included or listed in the solution explorer they should be compiled fine as the generation of the .h files will happen before any other compilation.
不要使用自定义构建工具选项,而是将其设置为解决方案的预构建事件(这可以采用通用命令行,就像自定义构建工具一样)。这样MSVS就不会检查生成的文件。只要它们是#included或列在解决方案资源管理器中,它们就应该被编译好,因为.h文件的生成将在任何其他编译之前发生。
I find the custom build tool is not so useful as the pre- and post- build events in general, because of the way it expects files to be generated or modified. You might find this tool useful for other things in the future (e.g. to compress the .exe after build, to generate other dependencies correctly, to ensure files are in place etc...)
我发现自定义构建工具通常不像构建前和构建后事件那么有用,因为它期望生成或修改文件的方式。您可能会发现此工具在将来对其他事情有用(例如,在构建后压缩.exe,正确生成其他依赖项,以确保文件到位等等)
There is a nice diagram showing where to find these options in the solution properties here
这里有一个很好的图表,显示在解决方案属性中找到这些选项的位置
#2
jheriko's answer is interesting, because it provides a way to launch custom tool, then generate build dependencies. But it's not very usable, because you then lose all possibilities to use "custom build tools" toolkit, in which you can
jheriko的回答很有意思,因为它提供了一种启动自定义工具的方法,然后生成构建依赖项。但它不是很有用,因为你失去了使用“自定义构建工具”工具包的所有可能性,你可以在其中使用
- choose to always compile files with some precise extension
- manually skip custom build for a particular file in a particular project configuration (and visualize this decision)
选择始终使用一些精确的扩展名编译文件
手动跳过特定项目配置中特定文件的自定义构建(并可视化此决策)
There is no way (or at least i have found none) to "have it all". The only way i have found is to have the custom build tool return a non-zero number when files have been updated, with a message to the user explaining that it is not an error and inviting him to launch build again. The next time, custom build tool is launched again (not optimal, but the tool i use is pretty fast) but modifies no new file, and build process goes on, using valid dependencies.
没有办法(或者至少我没有发现任何东西)“拥有一切”。我找到的唯一方法是让文件更新时自定义构建工具返回非零数字,并向用户发送一条消息,说明这不是错误并邀请他再次启动构建。下一次,自定义构建工具再次启动(不是最佳的,但我使用的工具非常快)但不修改新文件,并使用有效的依赖项继续构建过程。
Note : the approach described above does not work with Incredibuild, which seems to ignore project build order.
注意:上述方法不适用于Incredibuild,它似乎忽略了项目构建顺序。