Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Thanks for any ideas

like image 791
Andreas Schabus Avatar asked Mar 09 '23 09:03

Andreas Schabus


1 Answers

Yes that's certainly possible using the built-in globber features, 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));
    }
});

Similarly you can do the same before build with nuget restore, example

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

And a clean task could be adapted 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);
    }
});
like image 118
devlead Avatar answered Mar 15 '23 08:03

devlead