2017-04-12 95 views

回答

5

是的,這當然可以使用內置的通配符處理功能,例如:

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恢復,例如

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