csharp/build.cake (66 lines of code) (raw):
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Parse version from gradle.properties
var gradleProperties = new Dictionary<String, String>();
foreach (var row in System.IO.File.ReadAllLines("../gradle.properties"))
gradleProperties.Add(row.Split('=')[0], String.Join("=",row.Split('=').Skip(1).ToArray()));
var version = gradleProperties["version"];
var index = version.IndexOf("-");
var dotNetVersion = (index > 0 ? version.Substring(0, index) : version); // + ".0";
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
DotNetCoreClean("./Zstandard.sln",
new DotNetCoreCleanSettings { Configuration = configuration }
);
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore("./Zstandard.sln");
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
DotNetCoreBuild("./Zstandard.sln", new DotNetCoreBuildSettings {
Configuration = configuration,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", version)
.WithProperty("FileVersion", dotNetVersion)
.WithProperty("AssemblyVersion", dotNetVersion)
});
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
Information("Running tests");
DotNetCoreTest("./test/Zstandard.Tests.csproj",
new DotNetCoreTestSettings()
{
Configuration = configuration,
NoBuild = true,
Verbosity = DotNetCoreVerbosity.Quiet
}
);
});
Task("Pack")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = "./artifacts/",
MSBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", version)
.WithProperty("FileVersion", dotNetVersion)
.WithProperty("AssemblyVersion", dotNetVersion)
};
DotNetCorePack(".", settings);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Run-Unit-Tests");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);