Sal007
Sal007

Reputation: 67

how to search through the directory structure and get the .sln file name using MSBuild

I am setting up a build environment for few projects. Each project has more than one solution. I am in need of building all the solutions that will fall in different folders within a root directory. The lever of folder in with the solution files resides from the root directory can vary. That is the solutions file can be embedded with a folder which in turn can be with in another folder and so forth. How can I to search through the root directory structure and get the list of all the solutions (.sln) file name and its path using MSBuild so that I can build these solutions?

Similarly I would have to search for and get the list of all the dll and exe generated from the build so that I can run static code analysis on them. I am looking for a way that I can search and get the list of assemblies and their file path.

Upvotes: 2

Views: 538

Answers (1)

Brian Kretzler
Brian Kretzler

Reputation: 9938

This will find and report all solution files below the folder of the file this is placed in:

<Target Name="FindSolutions">
   <ItemGroup>
      <SolutionFile Include="$(MSBuildThisFileDirectory)\**\*.sln" />
   </ItemGroup>
   <Message Text="Found '%(SolutionFile.Identity)'" />
</Target>

The key is the ** which matches all folders recursively.

Upvotes: 3

Related Questions