如何在MSBuild中使用目标中的“输出"参数 [英] How to use an 'Output' parameter from a target in MSBuild

查看:82
本文介绍了如何在MSBuild中使用目标中的“输出"参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解一些MSBuild概念(我熟悉 NAnt )

I'm trying to understand some MSBuild concept (I'm familiar with NAnt).

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

I try to initialise some property in a target and then used it in another. Here is an example:

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

它当然不起作用.

推荐答案

除了在元素大小写方面存在一些较小的语法错误(即target-> Target)之外,还需要修复2个主要问题才能使其工作: br> 1)TaskParameter属性应设置为"TargetOutputs"
2)Sub目标的Outputs属性需要用引号引起来

Aside from some minor syntax errors in element case (i.e. target->Target), there are 2 main things that need to be fixed to make it work:
1) The TaskParameter attribute should be set to "TargetOutputs"
2) The Outputs attribute of the Sub target need to be surrounded in quotes

这是一个有效的示例:

<?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中使用目标中的“输出"参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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