Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the value of a MSBuild property from a custom task?

Is there some way to access the value of an MSBuild property from a custom task?

I know I can send them all in, but it would be nice not to :) I am trying to do this from a TFS build.

Or is there some way to access the "build script" currently running? Maybe like an object model and from there get what I need?

like image 719
Oddleif Avatar asked Nov 05 '22 21:11

Oddleif


1 Answers

This should do the job.

  public override bool Execute()
  {
    string projectFile = BuildEngine.ProjectFileOfTaskNode;

    Engine buildEngine = new Engine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory());

    Project project = new Project(buildEngine);
    project.Load(projectFile);
    foreach(var o in project.EvaluatedProperties)
    {
      // Use properties
    }

    return true;
  }
like image 184
Julien Hoarau Avatar answered Nov 14 '22 22:11

Julien Hoarau