从MsBuild任务返回输出? [英] Return output from an MsBuild task?
问题描述
我想计算一个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 Task调用另一个,并使用 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屋!