MSBuild - can I compile all solutions in child directories?

时间秒杀一切 提交于 2020-01-04 13:46:35

问题


Is there a way in MSBuild to compile all solutions in folders, and sub-folders, and sub... under a specified parent?

We have a bunch of sample programs we ship with our library. I want to add to the build process that we know they all compile.


回答1:


You can create own targets for restore and build operations. For example:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="EntryRestore" DefaultTargets="EntryMSBuild">

  <ItemGroup>
    <SolutionFile Include="./**/*.sln"/>
  </ItemGroup>

  <Target Name="EntryRestore">

    <Message Text="-----Entry-----" Importance="high"/>
    <Message Text="    Restore    " Importance="high"/>
    <Message Text="-----Entry-----" Importance="high"/>

    <MSBuild Projects="%(SolutionFile.Identity)" Targets="restore"/>
  </Target>

  <Target Name="EntryMSBuild">

    <Message Text="-----Entry-----" Importance="high" />
    <Message Text="     Build     " Importance="high" />
    <Message Text="-----Entry-----" Importance="high" />

    <MSBuild Projects="%(SolutionFile.Identity)" Targets="build"  />
  </Target>

</Project>

Item SolutionFile will contains paths for all .sln files that located in current directory and its subdirectories. You also may define path in CLI and perform searching relative it.

<ItemGroup>
  <SolutionFile Include="$(MyDir)/**/*.sln"/>
</ItemGroup>

MSBuild task launches MSBuild for performing specified targets. In our cas it are restore and build. It task used 'batching' that allow iterate over items by metadata.


&"D:\Visual Studio\MSBuild\15.0\Bin\msbuild.exe" .\Make.targets

MSBuild targets | Item element | Item metadata in task batching | MSBuild task



来源:https://stackoverflow.com/questions/51575248/msbuild-can-i-compile-all-solutions-in-child-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!