gpt4 book ai didi

msbuild - 如何在 MSBuild 中使用目标中的 'Output' 参数

转载 作者:行者123 更新时间:2023-12-02 21:07:26 24 4
gpt4 key购买 nike

我正在尝试理解一些 MSBuild 概念(我熟悉 NAnt )。

我尝试初始化目标中的某些属性,然后在另一个目标中使用它。这是一个例子:

<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>

这当然行不通。

最佳答案

除了元素大小写中的一些小语​​法错误(即目标->目标)之外,还有两个主要问题需要修复才能使其正常工作:
1) TaskParameter属性应设置为“TargetOutputs”
2)Sub目标的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>

以上输出:

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

关于msbuild - 如何在 MSBuild 中使用目标中的 'Output' 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5078759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com