How to call msbuild with wildcard in solution name (* .sln)?

I have some solution files (* .sln) in a folder. How can I call msbuild

for each one without explicitly specifying the solution name? The usual syntax is:

msbuild <solution-name>.sln /P:Configuration=<Debug,Release>

      

I tried this command, but obviously it is not supported:

msbuild *.sln /P:Configuration=<Debug,Release>

      

Is there a way to execute msbuild without knowing the solution name?

+3


source to share


1 answer


Use a for loop to iterate over the results dir *.sln

on the command line:

for %i in ( dir *.sln ) do ( msbuild %i /p:Configuration=Debug )

      



Or use the msbuild file to do the same. In the end, this can be a lot more interesting as it allows for more customization and automation. For example, the code shown below automatically generates both debug and release versions and can be extended for more. Also you can pass the directory to search for solutions and by default it selects the one where the msbuild file is located. This kind of thing is much more complicated and ugly on the command line or using batch files.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

  <PropertyGroup>
    <!-- directory where the solution files are -->
    <SlnDir Condition="'$(SlnDir)' == ''">$(MSBuildThisFileDirectory)</SlnDir>
  </PropertyGroup>

  <ItemGroup>
    <!-- list solution files -->
    <ProjectFiles Include="$(SlnDir)\*.sln"/>
    <!-- list configurations to build -->
    <Configurations Include="Debug;Release"/>
  </ItemGroup>

  <Target Name="Build">
    <MSBuild Projects="@(ProjectFiles)" Targets="Cli" Properties="Configuration=%(Configurations.Identity)"/>
  </Target>

</Project>

      

+3


source







All Articles