The file activity allows basic file attribute management operations to be performed by the build process. In this example we aim to show the the basic steps that are required to get the activity integrated into a build.

Before you can make use of any of the TFS community build activities you have to make sure they are available for the build system and on your development PC. Instructions for this process can be found in the ALM Rangers build guide or in the StyleCop page of this wiki. This page assumes the file activity is available in the developers build process workflow toolbox.

Editing the Workflow

Each instance of the file activity can perform one action. In this sample we will set the read only and system flags and alter the modified date on the DLLs produced by the build. To do this the file activity have been added twice at the end of the build process (as the last action in the agents sequence) as follows

image

The properties on each activity are set as follows

image

image

The possible actions and their related properties are as follows

Action Description Properties
AddAttributes Adds an attribute to a file(s) Required: Attributes, Files

Attributes supported (with limitations as to what can be added or removed)
  • Archive
  • Compressed*
  • Encrypted*
  • Hidden
  • Normal*
  • ReadOnly
  • System

* You can find the help topic for Win32's SetFileAttributes on MSDN

As mentioned in this help topic, the SetFileAttributes API cannot be used
to set any of the following file attributes:

  • FILE_ATTRIBUTE_COMPRESSED
  • FILE_ATTRIBUTE_DEVICE
  • FILE_ATTRIBUTE_DIRECTORY
  • FILE_ATTRIBUTE_ENCRYPTED
  • FILE_ATTRIBUTE_REPARSE_POINT
  • FILE_ATTRIBUTE_SPARSE_FILE

These are special attributes that must be set through other means, like
using the Win32 DeviceIoControl API, for example.

GetChecksum Gets the checksum of a file Required: Path
Output: Checksum
GetTempFileName Gets the path to the Windows temp file Output: Path
Move Moves a file Required: Path, TargetPath
RemoveAttributes Removes an attribute to a file(s) Required: Attributes, Files
See AddAttributes above
Replace Replaces files that machine a given expression Required: RegexPattern
Optional: Replacement, Path, TextEncoding, Files
SetAttributes Sets an attribute for a file(s) Required: Attributes, Files
See AddAttributes above
Touch Touches a file(s) so it access date is updated Required: Files
Optional: Force, Time
Delete Deleted a file(s) Required: Files
Optional: Force

The activity properties are as follows

Property Direction Comment
Path InOutArgument<string> A path to process or get. Use * for recursive folder processing. For the GetChecksum TaskAction, this indicates the path to the file to create a checksum for.
RegexPattern InArgument<string> Sets the regex pattern
Replacement InArgument<string> The replacement text to use. Default is string.Empty
Files InArgument<IEnumerable<string>> An ItemList of files to process. If calling SetAttributes, RemoveAttributes or AddAttributes, include the attributes in an Attributes metadata tag, separated by a semicolon.
Note the Files property cannot contain wildcards. if you wish to use a wildcard you need to use a FileMatchingFile activity as used with the StyleCop activity
TargetPath InArgument<string> Sets the TargetPath for a renamed file
Checksum OutArgument<string> Gets the file checksum
Force InArguement<bool> Forces the action on read only files
Time InArguement<DateTime> Date and time to use for touch. If not specify, the activity will use the current date and time.

Running the Build

When the build using this template is run (using a solution with two class library projects) we can see in the drops location that classlibrary1.dll has its attributes changed, and classlibrary2.dll has its modified date changed

 

image

Last edited Mar 27, 2012 at 3:33 PM by rfennell, version 2

Comments

almeidaalex Aug 14, 2012 at 1:27 PM 
I can't use Move action, should I set some value to Path property? However I can't, I filled TargetPath and Files properties, but I've been got the same error: "Invalid file passed"
Is it really necessary fill the Path property?