I have an MSBuild target which transforms a file in place, that is the input and output file is the same file. How do I get Visual Studio to handle the integration build properly in this case? Must I necessarily move the file?
1 Answer
A short answer: never transform file in place during the build. Any transformation should necessarily create a new file in some other location, or with a different name.
Long answer. MSBuild tracks if file is up-to-date based on time stamps. This is the same mechanism used by make and most of other build systems. This allows your incremental builds perform a partial rebuild of only necessary build steps. Note, that in order to make incremental builds work, you have to declare all input and output files in target's Inputs and Outputs attributes. If you have the same file in Inputs as well as in Outputs, it will be considered up-to-date and target would not be executed, which breaks your build.
If you don't care about incremental build, you can actually make it work, by simply creating a target that has no Inputs and Outputs. In this case target will always be executed. That comes with a price that you are doing full build every time.
9 Comments
$(TargetPath), it just specifies it as its output... It doesn't even drop a file there.