如何将物品压平成物业?

时间:2013-06-27 08:02:28

标签: msbuild msbuild-4.0

如何将物品压平成物业?

根据这个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:表达式“Project-to-import = @(RuntimeProj)”不能在此上下文中使用。项目列表不能与其他需要项目列表的字符串连接。使用分号分隔多个项目列表。

  

1 个答案:

答案 0 :(得分: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>