2011-01-23 36 views
32

輸出變量值的日誌如何輸出變量值到日誌從的MSBuild?如何從的MSBuild

我試圖調試一個MSBuild腳本,想輸出變量的值到日誌中。

+0

我認爲這個問題可能會幫助您解決問題。 http://stackoverflow.com/questions/2968077/trouble-with-outputting-msbuild-variables – awright18 2011-01-23 02:22:08

回答

55

你其實可以debug msbuild腳本與VS2010現在。它需要一些黑客攻擊,並沒有官方支持,但它是一種選擇。

否則使用Message任務。用於引用PropertiesItemsItem 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 
+3

爲了讓您的答案更易於使用,請考慮爲每個Message元素添加Importance =「high」屬性。這樣的消息時默認調用的MSBuild或者如果你在VS – 2015-05-10 08:49:13