MSBuild构建序列

时间:2010-06-07 17:58:15

标签: msbuild msbuild-task

从MS查看此article,我对SolutionToBuild部分有疑问。

<ItemGroup>
    <SolutionToBuild Include="$(SolutionRoot)\path\MySolution.sln />
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\scribble.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\HelloWorld\HelloWorld.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\TestProject1\TestProject1.sln" />
</ItemGroup>

它表示构建的顺序由上面的顺序决定。因此,例如,MySolution将在涂鸦之前构建。

但是,如果在MySolution上涂鸦是依赖,这是否安全?例如,MySolution输出scribble使用的一个或多个dll。如果同时更改MySolution和scribble,构建是否会等待MySolution完全编译,然后再转到下一个项目?

2 个答案:

答案 0 :(得分:5)

您可以尝试为项目SolutionToBuild使用其他元数据。有些人使用递归和voilà!

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\levelone.sln">
        <DependsOnSolutions>$(SolutionRoot)\Scribble\leveltwo.sln</DependsOnSolutions>
    </SolutionToBuild>        
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\leveltwo.sln">
        <DependsOnSolutions>$(SolutionRoot)\Scribble\levelthree.sln;$(SolutionRoot)\TestProject1\TestProject1.sln</DependsOnSolutions>
    </SolutionToBuild>
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\levelthree.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\TestProject1\TestProject1.sln" />
</ItemGroup>

<Target Name="Build">
    <MSBuild Projects="$(MSBuildProjectFile)"
             Targets="BuildSolution"                 
             Properties="SolutionFullPath=%(SolutionToBuild.Identity)"/>
</Target>

<Target Name="BuildSolution">   
    <CreateItem Condition="'%(SolutionToBuild.Identity)'=='$(SolutionFullPath)'"
        Include="%(SolutionToBuild.DependsOnSolutions)">
        <Output TaskParameter="Include"
                ItemName="DependentSolutions" />
    </CreateItem>

    <Message Text="Building solution $(SolutionFullPath)..." />        
    <Message Text="Solution $(SolutionFullPath) depends on %(DependentSolutions.Identity)..." 
             Condition="'@(DependentSolutions)'!=''"/>
    <Message Text="Building dependent solutions..."
             Condition="'@(DependentSolutions)'!=''"/>

    <MSBuild Projects="$(MSBuildProjectFile)"
             Targets="BuildSolution"
             Properties="SolutionFullPath=%(DependentSolutions.Identity)"
             Condition="'@(DependentSolutions)'!=''"/>

    <!-- <MSBuild Projects="$(SolutionFullPath)" /> -->
    <Message Text="Building solution $(SolutionFullPath)... OK" />
</Target>
</Project>

答案 1 :(得分:1)

如何管理解决方案依赖关系?你不是在引用项目吗?我也对你的一些解决方案的“同步”变化感到困惑。请澄清这些变化的性质。

到目前为止,您的问题的答案是:

  1. 否。它们可以一个接一个地编译,但它是否有资格获得依赖?
  2. 是。如果序列是必需的,那么构建器将“等待”,直到构建每个解决方案(成功或错误),然后再移动到下一个。