0

First of the screenshot of my Build Definition Configure screen:enter image description here

TemplatePath is defined as string in my build definition file.

I have a custom Build Activity class that has a property:

 public class MyActivity: NativeActivity {
      public InArgurment<string> TemplatePath{ get; set;}
      public void Execute(NativeActivityContext context){
          //My Code goes here
      }   
}

What I want to do is to be able to pass in the value of the TF_BUILD_SOURCESDIRECTORY environment variable into TemplatePath.

Let's say the sources directory maybe C:\Build[BuildAgentId][TFS_Project][Build Definition]\src, I want to be able to receive this information when I use the following code in my Execute method.

string templateLoc = TemplatePath.Get(context);

The screenshot has one of the values that I've been trying pass in. No matter which value I tried to pass in, I still receive the exact string from the TemplatePath set in the build definition configuration. How do I make TFS Build evaluate the expression to provide me with the correct path: C:\Build[BuildAgentId][TFS_Project][Build Definition]\src\Template\Template.qvw

I've been searching and playing around with different ways to passing the TFS BUILD environment variables but was not able to figure out/find a solution to do so. I may have been searching for the wrong thing.

Thank you,

LUIS PEREIRA
  • 478
  • 4
  • 20
NPToita
  • 238
  • 2
  • 9

1 Answers1

0

First of all, you can directly retrieve the environment variables inside your customized activity code as below.

var sourceDirectory = System.Environment.GetEnvironmentVariable("TF_BUILD_SOURCESDIRECTORY");

Then pass the relative path by parameter and combine it inside the code.

In your case, you can't directly pass environment variables as string. It's only available for MSBuild arguments as MSDN mentioned. (https://msdn.microsoft.com/en-us/library/hh850448.aspx)

Here is another useful link here.

Sphinx
  • 186
  • 5