问题
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