How can I use a batch file to MSBuild solutions in multiple directories at once?

我怕爱的太早我们不能终老 提交于 2019-12-19 04:15:14

问题


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.


回答1:


  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



来源:https://stackoverflow.com/questions/9608927/how-can-i-use-a-batch-file-to-msbuild-solutions-in-multiple-directories-at-once

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