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

How to output a variable value to the log from MSBuild(如何从 MSBuild 将变量值输出到日志)
本文介绍了如何从 MSBuild 将变量值输出到日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

我正在尝试调试 MSBuild 脚本并希望将变量的值输出到日志.

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

推荐答案

其实可以现在使用 Visual Studio 2010 调试 MSBuild 脚本.它需要一些黑客攻击,并且不受官方支持,但它是一种选择.

You can actually debug MSBuild scripts with Visual Studio 2010 now. It requires some hacking, and it isn't officially supported, but it is an option.

否则使用 Message 任务.引用 Properties 的常规规则、项目Item Metadata(也称为 批处理)申请.

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 将变量值输出到日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)