Skip to content
This repository has been archived by the owner on Nov 28, 2020. It is now read-only.

Commit

Permalink
Added project.json for tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson committed Sep 7, 2016
1 parent 73d2d0b commit c672de4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
22 changes: 4 additions & 18 deletions .gitignore
Expand Up @@ -6,32 +6,18 @@
[Pp]ackages/
/[Aa]rtifacts/
/[Tt]ools/
*.sln.ide/

# .NET CLI
# .NET Core CLI
/.dotnet/
dotnet-install.sh*
/.packages/
dotnet-install.sh*
*.lock.json

# Visual Studio
.vs/
.vscode/
launchSettings.json
project.lock.json

# Build related
build-results/
tools/Cake/
tools/xunit.runners/
tools/xunit.runner.console/
tools/nuget.exe
tools/gitreleasemanager/
tools/GitVersion.CommandLine/
tools/Addins/
tools/packages.config.md5sum

# mstest test results
TestResults
*.sln.ide/

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
16 changes: 1 addition & 15 deletions build.ps1
Expand Up @@ -90,20 +90,6 @@ if (!(Test-Path $NugetPath)) {
(New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath);
}

###########################################################################
# INSTALL TOOLS
###########################################################################

$GitVersionVersion = "3.6.2"
$GitVersionPath = Join-Path $ToolPath "GitVersion.CommandLine.$GitVersionVersion/Cake.dll"
if (!(Test-Path $GitVersionPath)) {
Write-Host "Installing GitVersion..."
Invoke-Expression "&`"$NugetPath`" install GitVersion.CommandLine -Version $GitVersionVersion -OutputDirectory `"$ToolPath`"" | Out-Null;
if ($LASTEXITCODE -ne 0) {
Throw "An error occured while restoring GitVersion.CommandLine ($GitVersionVersion) from NuGet."
}
}

###########################################################################
# RUN BUILD SCRIPT
###########################################################################
Expand All @@ -121,7 +107,7 @@ $Arguments = @{
Push-Location
cd build
Write-Host "Restoring packages..."
Invoke-Expression "& dotnet restore --verbosity error"
Invoke-Expression "& dotnet restore ./project.json --verbosity error"
if($LASTEXITCODE -ne 0) {
Pop-Location;
exit $LASTEXITCODE;
Expand Down
25 changes: 19 additions & 6 deletions build/Utilities/BuildLifetime.cs
Expand Up @@ -7,6 +7,8 @@
using System.Text;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Restore;

public class BuildLifetime : FrostingLifetime<BuildContext>
{
Expand All @@ -32,7 +34,7 @@ public override void Setup(BuildContext context)
context.ForcePublish = context.Argument<bool>("forcepublish", false);

// Setup projects.
context.Projects = new Project[]
context.Projects = new Project[]
{
new Project { Name = "Cake.Frosting", Path = "./src/Cake.Frosting/project.json", Publish = true },
new Project { Name = "Cake.Frosting.Testing" ,Path = "./src/Cake.Frosting.Testing/project.json" },
Expand All @@ -41,6 +43,17 @@ public override void Setup(BuildContext context)
new Project { Name = "Cake.Frosting.Cli", Path = "./src/Cake.Frosting.Cli/project.json", Publish = true }
};

// Install tools
context.Information("Installing tools...");
context.DotNetCoreRestore("./build/tools.project.json", new DotNetCoreRestoreSettings
{
PackagesDirectory = "./tools",
Verbosity = DotNetCoreRestoreVerbosity.Error,
Sources = new[] {
"https://api.nuget.org/v3/index.json"
}
});

// Calculate semantic version.
var info = GetVersion(context);
context.Version = context.Argument<string>("version", info.Version);
Expand Down Expand Up @@ -68,7 +81,7 @@ private static BuildVersion GetVersion(BuildContext context)
OutputType = GitVersionOutput.BuildServer
});
}

GitVersion assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json
Expand All @@ -80,19 +93,19 @@ private static BuildVersion GetVersion(BuildContext context)
if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(semVersion))
{
context.Information("Fetching verson from first project.json...");
foreach(var project in context.Projects)
foreach (var project in context.Projects)
{
var content = System.IO.File.ReadAllText(project.Path.FullPath, Encoding.UTF8);
var node = Newtonsoft.Json.Linq.JObject.Parse(content);
if(node["version"] != null)
if (node["version"] != null)
{
version = node["version"].ToString().Replace("-*", "");
}
}
semVersion = version;
}

if(string.IsNullOrWhiteSpace(version))
if (string.IsNullOrWhiteSpace(version))
{
throw new CakeException("Could not calculate version of build.");
}
Expand All @@ -109,7 +122,7 @@ private static bool IsBuildTagged(BuildSystem buildSystem)
private static string GetEnvironmentValueOrArgument(BuildContext context, string environmentVariable, string argumentName)
{
var arg = context.EnvironmentVariable(environmentVariable);
if(string.IsNullOrWhiteSpace(arg))
if (string.IsNullOrWhiteSpace(arg))
{
arg = context.Argument<string>(argumentName, null);
}
Expand Down
2 changes: 1 addition & 1 deletion build/project.json
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"Autofac": "4.1.0",
"Cake.Frosting": "0.1.0-alpha0006",
"Cake.Frosting": "0.1.0-alpha0017",
"Newtonsoft.Json": "9.0.1",
"Microsoft.NETCore.App": {
"type": "platform",
Expand Down
9 changes: 9 additions & 0 deletions build/tools.project.json
@@ -0,0 +1,9 @@
{
"dependencies": {
"GitVersion.CommandLine": "3.6.2"
},
"frameworks": {
"net45": {
}
}
}

0 comments on commit c672de4

Please sign in to comment.