c++ - VS2010自定义生成.h文件的构建工具

标签 c++ visual-studio-2010 msbuild custom-build-step

我正在尝试在 VS2010 中集成自定义构建工具,该工具从源文件生成 .h 文件。我已经为该步骤创建了 .xml、.targets 和 .props。 XML 大部分是从 MASM 文件中复制粘贴的,并以:

<ItemType Name="FOO" DisplayName="Foo compiler" />
<FileExtension Name="*.foo" ContentType="FOO" />
<ContentType Name="FOO" DisplayName="Foo compiler" ItemType="FOO" />

这会将我所有的 .foo 文件映射到 .props 中定义的 Foo 编译器:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <PropertyPageSchema Include="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml" />
    <AvailableItemName Include="FOO">
      <Targets>FooCompile</Targets>
    </AvailableItemName>
  </ItemGroup>
  <UsingTask TaskName="FOO" TaskFactory="XamlTaskFactory" AssemblyName="Microsoft.Build.Tasks.v4.0">
    <Task>$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml</Task>
  </UsingTask>
  <Target Name="FooCompile" BeforeTargets="$(FOOBeforeTargets)" AfterTargets="$(FOOAfterTargets)" Condition="'@(FOO)' != ''" Outputs="%(FOO.Outputs)" Inputs="%(FOO.Identity);%(FOO.AdditionalDependencies);$(MSBuildProjectFile)" DependsOnTargets="_SelectedFiles">
    <Message Importance="High" Text="@(FOO)" />
    <FOO Condition="'@(FOO)' != '' and '%(FOO.ExcludedFromBuild)' != 'true'"
         CommandLineTemplate="%(FOO.CommandLineTemplate)"
         OutputFileName="%(FOO.OutputFileName)"
         Inputs="%(FOO.Identity)" />
  </Target>
</Project>

当我编译我的项目时,它成功识别并编译了我的 foo 文件:

1>FooCompile:
1>  apa.foo
1>FooCompile:
1>  banan.foo
1>ClCompile:
1>  test.cpp
1>  main.cpp

我的问题是为什么它为每个文件打印一次“FooCompile:”而 ClCompile 却不打印?有什么办法可以改变吗?

如果我更改一个 cpp 文件并构建,我还会为每个文件获得一次此输出,我想避免这种情况:

1>FooCompile:
1>Skipping target "FooCompile" because all output files are up-to-date with respect to the input files.
1>FooCompile:
1>Skipping target "FooCompile" because all output files are up-to-date with respect to the input files.

最佳答案

FooCompile 目标正在使用“目标批处理”,这会导致目标针对为输出属性 %(Foo) 指定的数组中的每个项目迭代一次。另一方面,ClCompile 目标使用整个项目数组@(ClCompile) 进行操作。

您可以更改记录器的详细程度以避免消息,指定/v:minimal,但当然您也可能会过滤掉其他信息。

关于c++ - VS2010自定义生成.h文件的构建工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7215872/

相关文章:

deployment - msbuild 的 SFTP 任务?

c++ - 指向静态数组,但在不使用 * 的情况下取消引用

c# - 当缺少 ArgumentNullException 参数名称

c++ - 对 vector os 字符串进行排序 c++ visual studio 2010 - 错误 C2784 无法推断模板参数

msbuild - 是否有任何 MSBuild 属性显示我们正在发布?

c# - CSC : error CS2001: Source file '.NETPortable,Version=v4.5,Profile=Profile78.AssemblyAttributes.cs' could not be found

javascript - 寻找将非转义字符串转换为转义字符串的工具

c++ - 如何寻找 "to the invalid address stated on the next line"错误

c++ - 如何修复 "The Procedure entry point SDL_ceilf could not be located in the dynamic link library"

c - 在 visual studio 的命令行中以 C 的形式作为标准输入文件