
Specifying Inputs and Outputs
A target can be built incrementally if the inputs and outputs are specified in the project file.
To specify inputs and outputs for a target
MSBuild can compare the timestamps of the input files with the timestamps of the output files and determine whether to skip, build, or partially rebuild a target. In the following example, if any file in the @(CSFile) item collection is newer than the hello.exe file, MSBuild will run the target; otherwise it will be skipped:
<Target Name="Build"
Inputs="@(CSFile)"
Outputs="hello.exe">
<Csc
Sources="@(CSFile)"
OutputAssembly="hello.exe"/>
</Target>
When inputs and outputs are specified in a target, either each output can map to only one input or there can be no direct mapping between the outputs and inputs. In the previous Csc Task, for example, the output, hello.exe, cannot be mapped to any single input – it depends on all of them.
Note: |
|---|
A target in which there is no direct mapping between the inputs and outputs will always build more often than a target in which each output can map to only one input because
MSBuild cannot determine which outputs need to be rebuilt if some of the inputs have changed.
|
Tasks in which you can identify a direct mapping between the outputs and inputs, such as the LC Task, are most suitable for incremental builds, unlike tasks such as Csc and Vbc, which produce one output assembly from a number of inputs.