Skip to content

Instantly share code, notes, and snippets.

@patriksvensson
Last active August 29, 2015 14:02
Show Gist options
  • Save patriksvensson/b14c25244b8e611ffa25 to your computer and use it in GitHub Desktop.
Save patriksvensson/b14c25244b8e611ffa25 to your computer and use it in GitHub Desktop.
OrigoDB build script
@echo off
:Build
cls
echo Restoring NuGet packages for solution...
"tools\nuget\nuget.exe" "restore" "src/OrigoDB.sln"
echo.
if not exist tools\Cake\Cake.exe (
echo Installing Cake...
tools\nuget\nuget.exe install Cake -OutputDirectory tools -ExcludeVersion -NonInteractive
echo.
)
SET BUILDMODE="Release"
IF NOT [%1]==[] (set BUILDMODE="%1")
echo Starting Cake...
"tools\Cake\Cake.exe" "build.csx" "-verbosity=verbose" "-config=%BUILDMODE%"
exit /b %errorlevel%
using System.Text.RegularExpressions;
var target = Argument("target", "NuGet");
var config = Argument("config", "Release");
var output = "./build";
var version = ParseVersion("./src/SharedAssemblyInfo.cs");
if(version == null)
{
// We make sure the version is set.
throw new InvalidOperationException("Could not parse version.");
}
////////////////////////////////////////////////
// TASKS
////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(output);
});
Task("Build")
.IsDependentOn("Clean")
.Does(() =>
{
MSBuild("./src/OrigoDB.sln", settings =>
settings.SetConfiguration(config)
.UseToolVersion(MSBuildToolVersion.VS2012)
.WithTarget("clean")
.WithTarget("build"));
});
Task("Copy")
.IsDependentOn("Build")
.Does(() =>
{
var pattern = "src/OrigoDB.*/bin/" + config + "/OrigoDB.*";
CopyFiles(pattern, output);
});
Task("Zip")
.IsDependentOn("Copy")
.Does(() =>
{
var root = "./build/";
var output = "./build/OrigoDB.Core.binaries." + version + "-" + config + ".zip";
var files = root + "/*";
// Package the bin folder.
Zip(root, output);
});
Task("NuGet")
.IsDependentOn("Zip")
.Does(() =>
{
NuGetPack("./OrigoDB.Core.nuspec", new NuGetPackSettings {
Version = version,
OutputDirectory = "./build",
Symbols = true
});
});
////////////////////////////////////////////////
// RUN TASKS
////////////////////////////////////////////////
Run(target);
////////////////////////////////////////////////
// UTILITIES
////////////////////////////////////////////////
private string ParseVersion(string filename)
{
var file = FileSystem.GetFile(filename);
using(var reader = new StreamReader(file.OpenRead()))
{
var text = reader.ReadToEnd();
Regex regex = new Regex(@"AssemblyVersion\(""(?<theversionnumber>\d+\.\d+\.\d+)""\)");
return regex.Match(text).Groups["theversionnumber"].Value;
}
}
@rofr
Copy link

rofr commented Jun 13, 2014

Typo on line 77, OpenRead is a method group, should be OpenRead()
Also I'm getting an error locating MSBuild:
Error: Could not find MSBuild at C:/Program Files (x86)/MSBuild/12.0/Bin/amd64/MSBuild.exe

@patriksvensson
Copy link
Author

Since I'm not currently analysing the sln-file, I default to MSBuild tool version 12 (VS2013 and NET451/452). You can get around this by setting the tool version manually until I've fixed this :)

If you really want to use MSBuild 12.0, you can install the .NET Framework 4.5.1 SDK which includes this (if I'm not incorrect).

   MSBuild("./src/OrigoDB.sln", settings => 
      settings.SetConfiguration(config)
         .UseToolVersion(MSBuildToolVersion.VS2012)
         .WithTarget("clean")
         .WithTarget("build")); 

(More information here https://github.com/cake-build/cake/blob/develop/src/Cake.Common/MSBuild/MSBuildToolVersion.cs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment