3

I am an intern with a start-up company. I don't know anything about Batch files, XML files, the command prompt, or msbuild. I only know the basics of C#.

I have been asked to make a batch file that allows a user to build ALL solutions in a directory, with seven subfolders, in one command. I know how to build one solution in a single folder (by using msbuild mysolution.sln), but to build many solutions from seven different folders is beyond me.

It is possible to make a batch file that allows msbuild to find all solution files in the subfolders and build them all at once?

Thanks in advance for anyone who can help.

user1015106
  • 45
  • 1
  • 5

1 Answers1

14
  1. Save following targets file as buildall.targets in the root of your solutions directory

    <Project ToolsVersion="4.0" 
             xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
             DefaultTargets="Default">
    
        <ItemGroup>
            <AllFiles Include=".\**\*.sln"/>
        </ItemGroup>
    
        <Target Name="Default">
             <MSBuild Projects="@(AllFiles)"/>
        </Target>
    
     </Project>
    
  2. Create batch file named BuildAll.cmd with following content: (change path to msbuild.exe depends on .NET Framework version you are using)

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild buildall.targets
    
  3. Run/execute BuildAll.cmd

See MSDN: How to: Select the Files to Build for more details on recursive folder traversal, especially "Specifying Inputs with Wildcards" part

sll
  • 61,540
  • 22
  • 104
  • 156
  • Thank you for the quick response. I have done as you've said (hopefully), but I am receiving this error: `error MSB4025: The project file could not be loaded. Unexpected end of file has occurred. The following elements are not closed: Project. Line 9, position 10` Do you know what that means? – user1015106 Mar 07 '12 at 21:34
  • 1
    @user1015106 it means you have made a copy/paste error, by missing at least the last line (with `` in it). Make sure you copy the complete "gray box" into the file `buildall.targets`. – Christian.K Mar 08 '12 at 06:13
  • Thank you, Christian K. and sll. I really appreciate your help. – user1015106 Mar 12 '12 at 17:11