如何从MSBuild向日志输出变量值 [英] How to output a variable value to the log from MSBuild

查看:167
本文介绍了如何从MSBuild向日志输出变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从MSBuild输出变量值到日志?

How to output a variable value to the log from MSBuild?

我正在尝试调试一个MSBuild脚本,并希望向日志输出一个变量值。

I am trying to debug an MSBuild script and would like to output a variables value to the log.

推荐答案

你实际上可以 debug msbuild 脚本与VS2010现在。它需要一些黑客,它不是官方支持,但它是一个选项。

You can actually debug msbuild scripts with VS2010 now. It requires some hacking and it isn't officially supported but it is an option.

否则使用 消息 任务。引用 属性 项目 项目元数据 (也称为批处理)申请。

Otherwise use the Message task. Normal rules for referencing Properties, Items and Item Metadata (also referred to as batching) apply.

此示例:

<Project DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <TestItem Include="test1" />
    <TestItem Include="test2" />
    <TestItem Include="test3" />
  </ItemGroup>
  <PropertyGroup>
    <TestProperty>Property Value</TestProperty>
  </PropertyGroup>

  <Target Name="TestMessage" AfterTargets="Build" >
    <!--Use $(Property Name) to reference a property-->
    <Message Text="$(TestProperty)" Importance="high"/>
    <!--Use @(Item Name) to output a semi-colon separated list of items on one line-->
    <Message Text="@(TestItem)" Importance="high"/> 
    <!--Use %(Item Name.Metadata Property Name) to call the Message task once for each item.-->
    <!--This will output each item on a separate line-->
    <Message Text="%(TestItem.Identity)" Importance="high"/> 
  </Target>
</Project>

将产生此输出:

Property Value
test1;test2;test3
test1
test2
test3

这篇关于如何从MSBuild向日志输出变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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