【发布时间】:2011-01-23 02:18:21
【问题描述】:
如何将变量值从 MSBuild 输出到日志?
我正在尝试调试 MSBuild 脚本并希望将变量的值输出到日志。
【问题讨论】:
-
我认为这个问题可能有助于解决您的问题。 stackoverflow.com/questions/2968077/…
如何将变量值从 MSBuild 输出到日志?
我正在尝试调试 MSBuild 脚本并希望将变量的值输出到日志。
【问题讨论】:
您现在实际上可以使用 Visual Studio 2010 debug MSBuild 编写脚本。它需要一些黑客攻击,并且不受官方支持,但它是一种选择。
否则使用Message 任务。引用Properties、Items 和Item Metadata(也称为batching)的常规规则适用。
这个例子:
<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
【讨论】:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 文件中,但我在输出中看不到任何内容。
Microsoft.Build.Exceptions.InvalidProjectFileException: The <Message> tag is no longer supported as a child of the <Project> element. Place this tag within a target, and add the name of the target to the "InitialTargets" attribute of the <Project> element.