我正在尝试在 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/