如何将一个项目扁平化为一个属性?
根据这个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) 不能在此上下文中使用。项目列表不能与需要项目列表的其他字符串连接。使用分号分隔多个项目列表。