vcxproj 第一次不构建生成的源代码 [英] vcxproj does not build generated source code the first time

查看:52
本文介绍了vcxproj 第一次不构建生成的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不包含源代码的 VS 2010 vcxproj.PreBuildEvent 调用一个批处理文件,该文件使用第三方工具将源代码生成到我的 src\ 目录中.这很好用.问题是第一次生成源代码时(或清理后),VisualStudio 并没有真正编译生成的源代码.在随后的构建中,它会编译.这对我的 CI 构建机器来说是一个问题,对开发人员来说也是一个问题.有没有办法让VS识别那些生成的文件?

I have a VS 2010 vcxproj that contains no source code. A PreBuildEvent calls a batch file that uses a third party tool to generate source code into my src\ directory. That works fine. The problem is that the first time the source code is generated (or after a clean), VisualStudio does not actually compile the generated source. On a subsequent build, it does compile. This is a problem for my CI build machine as well as annoying to developers. Is there any way to get VS to recognize those generated files?

这是我的 .vcxproj 的片段

Here's a snippet from my .vcxproj

<ItemDefinitionGroup>
  <PreBuildEvent>
    <Message>Generating from IDL </Message>
    <Command>genNAPIEMsgs.bat</Command>
  </PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
  <ClInclude Include="src\*.h" />
</ItemGroup>
<ItemGroup>
  <ClCompile Include="src\*.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ItemGroup>
  <DDSGeneratedFiles Include="src\*.cpp" />
  <DDSGeneratedFiles Include="src\*.h" />
</ItemGroup>
<Target Name="AfterClean">
  <Message Text="AfterClean target: removing generated source code" />
  <Delete Files="@(DDSGeneratedFiles)" />
</Target>

推荐答案

嗯,这是因为 msbuild 项目中的评估顺序.http://msdn.microsoft.com/en-us/library/dd997067.aspx

Well, it happens because of evaluation order in msbuild project. http://msdn.microsoft.com/en-us/library/dd997067.aspx

合并到编译中的 Cpp 文件被定义为全局项 ClCompile.因此,在执行任何目标之前对它们进行评估.在评估开始时,没有生成 cpp 文件,因此没有编译生成的文件.您可以通过目标的 Returns 属性修改 ClCompile 项.但据我所知 PreBuildEvent 目标不返回任何东西.因此,您可以将自己的目标注入到将修改 ClCompile 项的构建中.好吧,我还没有尝试过,但我会从这样的事情开始:

Cpp files that are incorporated into compilation are defined as global items ClCompile. So they are evaluated before any target is executed. At the moment evaluation is started there is none generated cpp file so none of generated files is compiled. You can modify ClCompile items by Returns attribute of target. But as far as I’m aware PreBuildEvent target does not Returns anything. So you can inject your own target into build that will modify ClCompile items. Well I haven’t tried it but I’d start with something like this:

<Target Name="AppendMyGeneratedFilesToClCompile" DependsOnTargets="PreBuildEvent" Returns="@(ClCompile)" >
    <ItemGroup>
       <ClCompile Include="src\*.cpp" />
    </ItemGroup>
</Target>

头文件对于 ClCompile 目标毫无意义.您可以将它们包含到 ClInclue 中,但不是必须的(从 msbuild 的角度来看,您不必将它们包含到 msbuild 项目中).

Header files are meaningless for ClCompile target. You can include them into ClInclue but don't have to (from msbuild perspective you don't have to include them into msbuild project).

这篇关于vcxproj 第一次不构建生成的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆