Visual Studio custom build event always executing

和自甴很熟 提交于 2019-12-10 16:13:37

问题


I am using the odb compiler as a custom build tool. The build tool is always executing even though the input file is not changing.

The command line:

odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient  
 -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query  
--generate-schema --schema-format separate 
c:\menuplan\src\ingredient\ing_odb_category.hpp`  

The input file is:
ing_odb_category.hpp.

The outputs:

ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx   

The additional dependencies:
ing_odb_category.hpp

The description:
odb ing_odb_category.hpp

The output from Visual Studio 2010:

2>------ Build started: Project: vs_2010, Configuration: Debug Win32 ------
2>  odb ing_odb_category.hpp

The odb tool takes the ing_odb_category.hpp as input and produces ing_odb_category-odb.hxx, ing_odb_category-odb.ixx,ing_odb_category-odb.cxx,ing_odb_category-schema.cxx files.

I can build the solution many times in a row and the custom build event will always run, even though the ing_odb_category.hpp file never changes.

How can I make Visual Studio only perform the custom build if the header file changes?

From the vcxproj file:

<CustomBuild Include="..\ing_odb_category.hpp">
  <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate  c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
  <Command Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb -Ic:\menuplan\src\ingredient -o c:\menuplan\src\ingredient -d mysql --hxx-prologue "#include \"odb/traits.hxx\"" --generate-query --generate-schema --schema-format separate  c:\menuplan\src\ingredient\ing_odb_category.hpp</Command>
  <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">odb ing_odb_category.hpp</Message>
  <Message Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">odb ing_odb_category.hpp</Message>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
  <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug_Static_Unicode|Win32'">ing_odb_category-odb.hxx;ing_odb_category-odb.ixx;ing_odb_category-odb.cxx;ing_odb_category-schema.cxx</Outputs>
  <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ing_odb_category.hpp</AdditionalInputs>
</CustomBuild>

Environment:

  • Visual Studio 2010
  • Windows 7 - 64bit

回答1:


Visual Studio was always building the files because it said they didn't exist.

Using the Visual Studio project logging article, especially running the DebugView showed that Visual Studio was using a different path for the dependencies. I did not specify the path of the output files and dependencies, so it was trying to locate them in the default project directory.

Also, Visual Studio expects only one output file, according to Specifying Custom Build Tools article. I was supplying all the output filenames.

Summary

In the Custom Build Tool window:

  1. There should only be one output file.
  2. Additional output files are listed in the Additional Dependencies slot.
  3. All output files should be prefixed with the path of their location, relative or absolute.

Useful build process debugging aids can be found in the Visual Studio Project Logging article, especially the DebugView application.



来源:https://stackoverflow.com/questions/28888014/visual-studio-custom-build-event-always-executing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!