2011-08-27 98 views
0

我试图在VS2010中集成一个自定义生成工具,该工具从源文件生成.h文件。我为这一步创建了一个.xml,.targets和.props。 XML是主要来自MASM文件复制粘贴,结尾是:VS2010定制生成工具,用于生成.h文件

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

这映射我的所有包含.foo文件到公司在.props定义的富编译:

<?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. 

回答

1

的FooCompile目标是利用“目标配料”,它使目标对为Outputs属性(%(Foo))指定的数组中的每个项目迭代一次。另一方面,ClCompile目标使用整个项目数组@(ClCompile)进行操作。

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

+0

设置输出=“@(FOO - >'%(OutputFileName)')”和Inputs =“@(FOO)...”使其工作得更好,但不能正常清理。我错过了一些步骤? – user408952

+0

你在做什么来支持清洁?它不是自动的,你需要自己接线。看看@(FileWrites)这可能就足够了(所有这些都在我的新书“MSBuild Trickery”中介绍) –