用于生成.h文件的VS2010自定义构建工具

VS2010 custom build tool for generating .h file

本文关键字:VS2010 自定义 构建 工具 文件 用于      更新时间:2023-10-16

我试图在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,但当然您也可能过滤掉其他信息。