Created
April 17, 2018 02:04
-
-
Save unquietwiki/58638b1504215796497cbdd2da5d2ed2 to your computer and use it in GitHub Desktop.
Example build.cake file for .NET Core 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```csharp | |
// https://github.com/Microsoft/msbuild/issues/2532 | |
// env var "MSBuildSDKsPath" needs to be set to the correct "sdks" subfolder | |
// Other refs: https://cakebuild.net/api/ & https://cakebuild.net/docs/fundamentals/asynchronous-tasks | |
using System.Threading; | |
using Cake.Common.Tools.DotNetCore; | |
using Cake.Common; | |
var target = Argument ("target", "Default"); | |
var programProjects = new [] { | |
"./src/Exe1/Exe1.csproj", | |
"./src/Exe2/Exe2.csproj", | |
}; | |
// Its possible the Linux Subsystem on Windows may say Linux is present; not sure. | |
// In any case, make sure the .csproj files are also correct! | |
string runtimeString(){ | |
if (IsRunningOnWindows()) return "win-x64"; | |
return "linux-x64"; | |
} | |
// First build a functions library, then build EXEs in parallel | |
Task ("Default") | |
.IsDependentOn ("Build_Library") | |
.Does (() => BuildInParallel (programProjects)); | |
// Critical task: build a common functions library | |
Task ("Build_Library") | |
.Does (() => DotNetCorePublish ("./src/Library/Library.csproj", new DotNetCorePublishSettings { | |
Framework = "netstandard2.0", | |
Configuration = "Release", | |
OutputDirectory = "./bin/", | |
Runtime = runtimeString() | |
})); | |
// Parallel build task: build the EXEs | |
public void BuildInParallel ( | |
IEnumerable<string> filePaths, | |
int maxDegreeOfParallelism = -1, | |
CancellationToken cancellationToken = default (CancellationToken)) { | |
// Create an array of actions, based on the number of given projects | |
var actions = new List<Action> (); | |
var settings = new DotNetCorePublishSettings { | |
Framework = "netcoreapp2.0", | |
Configuration = "Release", | |
OutputDirectory = "./bin/", | |
Runtime = runtimeString() | |
}; | |
foreach (var filePath in filePaths) { | |
actions.Add (() => DotNetCorePublish (filePath, settings)); | |
} | |
// Fire off parallel jobs, based on array of actions | |
Parallel.Invoke (new ParallelOptions { | |
MaxDegreeOfParallelism = maxDegreeOfParallelism, | |
CancellationToken = cancellationToken | |
}, actions.ToArray ()); | |
} | |
// Entry point | |
RunTarget (target); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment