Since Microsoft doesn’t seem to be interested in publishing docs on built-in TF Build 2010 Activities, I’ll be publishing blog posts about activities that I’ve worked and/or experimented with. The titles will be the full name of the activity class with the hope that it’ll come up near the top on searches. The information here is a result of analysis of the activity from .NET Reflector as well as testing and experimentation in the context of a TFS 2010 Build Server but should not be construed as “official documentation”.
This activity will expand Environment Variables specified in the standard MSBuild property syntax. For example, $(WinDir) will be expanded to the Windows directory on the current machine. Note that this may be different for the controller and the agent and will reflect the current machine context based on where it is executed in the build process. Because of that, be careful if you evaluate/cache results between these contexts.
The syntax is similar to an MSBuild property. For example, to expand the %WINDIR% environment variable, use $(WINDIR).
Note that this method only includes standard environment variables by default and does not include any default MSBuild or TFBuild (<2010) variables. Internally, it uses a regular expression to identify properties identified as $([VarName]). It first tries to resolve the matches using System.Environment::GetEnvironmentVariable. If that fails, it then looks in the dictionary supplied in the AdditionalVariables property.
Like MSBuild properties, this will use the $(PropName) syntax. For example, to expand %WinDir%, you will use $(WinDir).
While this activity does have its uses, there are some key variables missed. For example, any and all variables that were available in TF Build < 2010. This makes things very difficult to have a single template that can be used across many projects. To help with this, you can use the AdditionalVariables property and add any (custom) expansion variables that you want to, making this activity far more useful.
I will be creating activities to do this that will be available as a part of the Community TFS Build Extensions and may also be available separately. I’m planning a single, code-based activity to do one variable at a time as well as a composite activity that will do the standard TFS Build 2008 properties. In the meantime, you can download an example build process template here. It adds a couple of those TF Build <= 2008 standard properties as AdditionalVariables and also shows how to call a standard environment variable.
Once you figure this activity out, it’s pretty simple and can be highly useful. However, the lack of documentation (are you listening Microsoft DevDiv?) makes it far more complicated than it really needs to be. One should not need to use Reflector to understand how a Microsoft-supplied component works.