Varun K
Varun K

Reputation: 3638

The output parameter 'CopiedFiles' of Copy task is returning all the files specified to copy even if it copies nothing given SkipUnchangedFiles="true"

The CopiedFiles parameter is returning all the files that were intended to be copied. But given the fact that SkipUnchangedFiles is set to true and ttask itself is not copying anything as can be seen on command line (no copying message). Why not, then, CopiedFiles is empty?

I need to have CopiedFiles parameter be populated only with files that were actually copied (because they were changed) in order to further copy these files into some other folder. This is to maintain an up-to-date release folder as well as to extract only those files which actually need to be propogated onto UAT/production server.

For reference sake, the copy task code I'm using is given below:

<Copy SkipUnchangedFiles="true"
            SourceFiles="@(cfile)"
                DestinationFiles="@(cfile->'$(PublishDir)\%(Identity)')">

        <Output
                    TaskParameter="CopiedFiles"
                    ItemName="Changed" />

</Copy>

<Message Text="changed:@(Changed)" Importance="high" />

Is there a bug in the copy task or this is the intended behavior.

Upvotes: 4

Views: 3517

Answers (1)

Brian Kretzler
Brian Kretzler

Reputation: 9938

The behavior you are seeing is by design. MSBuild keeps track of file dependencies using task outputs. If it were to do otherwise, anything that relied on the @(Changed) item array as an input would not fully process all of the files it needed in most cases. It will even keep track of properties and items created within targets that don't even execute when Inputs and Outputs are up-to-date, for the same reason. Consider making a different Copy task of your own with an additional output parameter, CopiedFilesCopiedByTask (this naming mirrors the naming and behavior of the ValueSetByTask in the otherwise defunct CreateProperty task).

Upvotes: 3

Related Questions