使用 Cake(C# make)在树中构建所有解决方案?
Build all solutions within a tree using Cake (C# make)?
我在同一个目录树中有多个 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);
}
});
我在同一个目录树中有多个 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);
}
});