如何使用';输出';MSBuild中目标的参数
我试图理解一些MSBuild概念(我很熟悉) 我尝试在一个目标中初始化一些属性,然后在另一个目标中使用它。以下是一个例子:如何使用';输出';MSBuild中目标的参数,msbuild,Msbuild,我试图理解一些MSBuild概念(我很熟悉) 我尝试在一个目标中初始化一些属性,然后在另一个目标中使用它。以下是一个例子: <propertygroup> <MyProp>X</MyProp> </propertygroup> <target name="Main"> <message text="$(MyProp)"/> <!-- Display 'X' --> <CallTar
<propertygroup>
<MyProp>X</MyProp>
</propertygroup>
<target name="Main">
<message text="$(MyProp)"/> <!-- Display 'X' -->
<CallTarget Target="Sub">
<Output TaskParameter="localProp" PropertyName="MyProp"/>
</CallTarget>
<message text="$(MyProp)"/> <!-- should display 'Y' -->
</target>
<target name="Sub" Outputs=$(localProp)>
<propertygroup>
<localProp>Y</localProp>
</propertygroup>
</target>
X
Y
当然,它不起作用。您将目标上定义的输出与任务的输出参数相混淆 目标的输出用于相关性分析: 任务的输出参数用于返回数据:
除了元素大小写中的一些小语法错误(即target->target),还有两个主要问题需要解决才能使其正常工作:
1) TaskParameter属性应设置为“targetOutput”
2) 子目标的Outputs属性需要用引号括起来 这是一个工作示例:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Main">
<PropertyGroup>
<MyProp>X</MyProp>
</PropertyGroup>
<Target Name="Main">
<Message text="$(MyProp)"/> <!--display 'X'-->
<CallTarget Targets="Sub">
<Output TaskParameter="TargetOutputs" PropertyName="MyProp"/>
</CallTarget>
<Message text="$(MyProp)"/> <!-- should display 'Y'-->
</Target>
<Target Name="Sub" Outputs="$(localProp)">
<PropertyGroup>
<localProp>Y</localProp>
</PropertyGroup>
</Target>
</Project>
thx,我已经阅读了所有的文档。但我不明白里面有什么话。。。梅比,你能给我举个例子说明我想做什么吗?你想做什么?如果要调用将为您设置某些属性的对象,则可以编写一个直接设置属性的目标,或编写一个自定义任务,使用任务下的Output元素(如答案中的简单示例链接)设置复制到属性中的输出。
Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 5/6/2016 9:51:37 AM.
Project "C:\workspace\dev\msbuild\temp.msbuild" on node 1 (default targets).
Main:
X
Y
Done Building Project "C:\workspace\dev\msbuild\temp.msbuild" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.07