从 MsBuild 任务返回输出? [英] Return output from an MsBuild task?

查看:16
本文介绍了从 MsBuild 任务返回输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算一个 MsBuild 任务中的路径,以供另一个 MsBuild 任务使用.实现这一目标的最佳方法是什么?

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

推荐答案

使用属性或项目.计算路径的 MSBuild,将其作为属性返回,然后将此属性用作其他任务的输入.

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>

如果您需要在两个 MSBuild 项目之间传递值,则应创建第三个项目,该项目将使用 MSBuild 任务调用另一个项目,并使用 TargetOutputs 元素取回所需的值.

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.

这篇关于从 MsBuild 任务返回输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆