c# - 使用 Cake(C# make)在树中构建所有解决方案?

标签 c# msbuild cakebuild

我在同一个目录树中有多个 VS 解决方案,我想使用 Cake 构建所有这些解决方案。有没有一种方法可以构建所有这些而无需将它们一个一个地放入构建脚本中?

感谢任何想法

最佳答案

是的,使用内置的 globber 功能当然可以,例如:

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));
    }
});

同样,您可以在使用 nuget restore 构建之前执行相同的操作,例如

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

一个干净的任务可以这样改编

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);
    }
});

关于c# - 使用 Cake(C# make)在树中构建所有解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43373510/

相关文章:

c# - CAKE 中的加载指令可以用于可选文件吗?

c# - 强制约束问题

c# - 套接字无响应

c# - 如何使用 ADO.NET 创建数据库触发器

c# - 在 C# 中移动 Form2 时移动 Form1

configuration - RunCodeAnalysis = true在命令提示符(MSBuild)中不起作用

c# - vscode 有 csproj 生成器吗?

visual-studio - 调用 devenv 时传递 MSBuild 选项

c# - 如何在 Cake 任务的 `WithCriteria` 中使用全局变量?

c# - 是否可以从 Cake 任务中调用 powershell 命令