Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return output from an MsBuild task?

I'd like to calculate a path in a MsBuild task, to be used by another MsBuild task. What is the best way to accomplish this?

Setting a environment variable, printing to Console, ...?

like image 369
ripper234 Avatar asked Sep 03 '09 12:09

ripper234


1 Answers

Use a property or an item. Your MSBuild that calculates the path, return it as a property and you use this property as input for your other task.

public class CalculatePathTask : ITask {     [Output]     public String Path { get; set; }      public bool Execute()     {                                            Path = CalculatePath();          return true;     } } 
<Target Name="CalculateAndUsePath">   <CalculatePathTask>     <Output TaskParameter="Path" PropertyName="CalculatePath"/>   </CalculatePathTask>    <Message Text="My path is $(CalculatePath)"/> </Target> 

If you need to pass a value between two MSBuild project, you should create a third one that will call the other using MSBuild Task and use the TargetOutputs element to get back the value that you want.

like image 144
Julien Hoarau Avatar answered Oct 07 '22 06:10

Julien Hoarau