2011-08-27 97 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」中介紹) –