Build all solutions in a tree using Cake (C # make)?

I have several VS solutions in the same directory tree and would like to build them all using Cake. Is there a way to build them all without putting them one by one in the build script?

Thanks for any ideas

+3


source to share


1 answer


Yes, of course it is possible to use the built-in globber functions, for example:

var solutions           = GetFiles("./**/*.sln");

Task("Build")
    .IsDependentOn("Clean")
    .IsDependentOn("Restore")
    .Does(() =>
{
    // Build all solutions.
    foreach(var solution in solutions)
    {
        Information("Building {0}", solution);
        MSBuild(solution, settings =>
            settings.SetPlatformTarget(PlatformTarget.MSIL)
                .WithProperty("TreatWarningsAsErrors","true")
                .WithTarget("Build")
                .SetConfiguration(configuration));
    }
});

      

Likewise, you can do the same before build with nuget restore like



Task("Restore")
    .Does(() =>
{
    // Restore all NuGet packages.
    foreach(var solution in solutions)
    {
        Information("Restoring {0}...", solution);
        NuGetRestore(solution);
    }
});

      

And one could set up a pure task like this

var solutionPaths       = solutions.Select(solution => solution.GetDirectory());

Task("Clean")
    .Does(() =>
{
    // Clean solution directories.
    foreach(var path in solutionPaths)
    {
        Information("Cleaning {0}", path);
        CleanDirectories(path + "/**/bin/" + configuration);
        CleanDirectories(path + "/**/obj/" + configuration);
    }
});

      

+6


source







All Articles