2013-06-27 77 views
2

如何將物品壓扁成物業?如何將物品拼合成物業?

根據這MSDN page (section Conversions between Strings and Item Lists),它只是一個聲明屬性與物品作爲價值的問題。

但我發現實際做法完全相反。當我運行這個項目的MSBuild 4.0,指定目標install ...

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Import Project="$(Project-to-import)" Condition="'$(Project-to-import)' != ''" /> 

    <ItemGroup> 
    <RuntimeProj Include="C:\TEMP\Design.proj" /> 
    <DesigntimeProj Include="C:\TEMP\Run.dproj" /> 
    </ItemGroup> 

    <PropertyGroup> <!-- Flatten out the items to properties. --> 
    <RuntimeProj>@(RuntimeProj)</RuntimeProj> 
    <!--^This bit doesn't work. MS documentation is wrong? --> 
    <DesigntimeProj>@(RuntimeProj)</DesigntimeProj> 
    </PropertyGroup> 

    <Target Name="install"> 
    <Message Text="Hello world!"/> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildRunPackage" 
      Properties="Project-to-import=$(RuntimeProj)" /> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildDesignPackage" 
      Properties="Project-to-import=$(DesigntimeProj)" /> 
    </Target> 

    <Target Name="BuildRunPackage"> 
    <CallTarget Targets="Clean" /> 
    <CallTarget Targets="Build" /> 
    </Target> 

    <Target Name="BuildDesignPackage"> 
    <CallTarget Targets="Clean" /> 
    <CallTarget Targets="Make" /> 
    <CallTarget Targets="Register" /> 
    </Target> 
<.Project> 

...返回一個錯誤......

錯誤MSB4012:表達式「項目,TO-進口= @(RuntimeProj)不能在這種情況下使用。項目列表不能與其中一個項目列表,預計其他字符串並置。使用分號來分隔多個項目清單。

回答

4

我不是很確定,但我認爲你會陷入評估訂單問題。 據我知道屬性評估之前項目(請參閱http://msdn.microsoft.com/en-us/library/dd997067.aspx中的屬性和項目評估順序) 如果您可以嘗試從安裝目標下的「全局」移動屬性組。它應該工作。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Import Project="$(Project-to-import)" Condition="'$(Project-to-import)' != ''" /> 

    <ItemGroup> 
    <RuntimeProj Include="C:\TEMP\Design.proj" /> 
    <DesigntimeProj Include="C:\TEMP\Run.dproj" /> 
    </ItemGroup> 


    <Target Name="install"> 
    <PropertyGroup> <!-- Flatten out the items to properties. --> 
     <RuntimeProj>@(RuntimeProj)</RuntimeProj> 
     <DesigntimeProj>@(RuntimeProj)</DesigntimeProj> 
    </PropertyGroup> 

    <Message Text="Hello world!"/> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildRunPackage" 
      Properties="Project-to-import=$(RuntimeProj)" /> 
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="BuildDesignPackage" 
      Properties="Project-to-import=$(DesigntimeProj)" /> 
    </Target> 

    <Target Name="BuildRunPackage"> 
    <CallTarget Targets="Clean" /> 
    <CallTarget Targets="Build" /> 
    </Target> 

    <Target Name="BuildDesignPackage"> 
    <CallTarget Targets="Clean" /> 
    <CallTarget Targets="Make" /> 
    <CallTarget Targets="Register" /> 
    </Target> 
</Project> 
+0

是的。這是做到這一點的方法。你必須在''中平整屬性。 –