Return output from an MsBuild task?

南笙酒味 提交于 2019-11-27 02:31:17

问题


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, ...?


回答1:


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.



来源:https://stackoverflow.com/questions/1372997/return-output-from-an-msbuild-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!