我有一个需要生成然后验证的文件类型,使用 2 个单独的工具。我想尽可能递增地执行此操作,因此我想创建一个 0 文件标记,以记住上次验证生成的文件的时间。我设法让生成只在修改后的文件上重新运行,而不是验证。
例如,假设这是 .targets:
<Project ToolsVersion="4.0" DefaultTargets="Validate" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MyItem Include="itemA" />
<MyItem Include="itemB" />
</ItemGroup>
<Target Name="Generate"
Inputs="@(MyItem)"
Outputs="@(MyItem->'%(Filename).gen')">
<Copy SourceFiles="@(MyItem)" DestinationFiles="@(MyItem->'%(Filename).gen')" />
</Target>
<Target Name="Validate" DependsOnTargets="Generate"
Inputs="@(MyItem->'%(Filename).gen')"
Outputs="@(MyItem->'%(Filename).gen.validated')">
<!-- Do validation stuff... -->
<Touch AlwaysCreate="true" Files="@(MyItem->'%(Filename).gen.validated')" />
</Target>
</Project>
我第一次运行它,它会生成并验证这两个项目 - 这很好:
> msbuild
Generate:
Copying file from "itemA" to "itemA.gen".
Copying file from "itemB" to "itemB.gen".
Validate:
Creating "itemA.gen.validated" because "AlwaysCreate" was specified.
Creating "itemB.gen.validated" because "AlwaysCreate" was specified.
再次运行它,什么也没做——太好了:
> MSBuild
Generate:
Skipping target "Generate" because all output files are up-to-date with respect to the input files.
Validate:
Skipping target "Validate" because all output files are up-to-date with respect to the input files.
现在只更改 itemA:
> touch itemA
> MSBuild
Generate:
Building target "Generate" partially, because some output files are out of date with respect to their input files.
Copying file from "itemA" to "itemA.gen". <<<<< Good - MSBuild knows not to generate itemB.gen
Validate:
Touching "itemA.gen.validated".
Touching "itemB.gen.validated". <<<< Bad - how can I tell MSBuild to skip validation of itemB
那么,我怎样才能告诉 MSBuild 也Validate
部分运行我的目标呢?