Skip to content

Commit 746f7e1

Browse files
committed
Removed VS XUnit runner and added Cake script
1 parent 98804b2 commit 746f7e1

File tree

7 files changed

+245
-11
lines changed

7 files changed

+245
-11
lines changed

build/build.cake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#tool "nuget:?package=xunit.runner.console"
2+
//////////////////////////////////////////////////////////////////////
3+
// ARGUMENTS
4+
//////////////////////////////////////////////////////////////////////
5+
6+
var target = Argument("target", "Default");
7+
var configuration = Argument("configuration", "Release");
8+
9+
//////////////////////////////////////////////////////////////////////
10+
// PREPARATION
11+
//////////////////////////////////////////////////////////////////////
12+
13+
// Define directories.
14+
var solutionFile = "../src/SimpleEventStore/SimpleEventStore.sln";
15+
16+
//////////////////////////////////////////////////////////////////////
17+
// TASKS
18+
//////////////////////////////////////////////////////////////////////
19+
20+
Task("Restore-NuGet-Packages")
21+
.Does(() =>
22+
{
23+
NuGetRestore(solutionFile);
24+
});
25+
26+
Task("Build")
27+
.IsDependentOn("Restore-NuGet-Packages")
28+
.Does(() =>
29+
{
30+
// Use MSBuild
31+
MSBuild(solutionFile, settings => settings.SetConfiguration(configuration));
32+
});
33+
34+
Task("Run-Unit-Tests")
35+
.IsDependentOn("Build")
36+
.Does(() =>
37+
{
38+
XUnit2("../src/**/bin/" + configuration + "/*.Tests.dll");
39+
});
40+
41+
//////////////////////////////////////////////////////////////////////
42+
// TASK TARGETS
43+
//////////////////////////////////////////////////////////////////////
44+
45+
Task("Default")
46+
.IsDependentOn("Run-Unit-Tests");
47+
48+
//////////////////////////////////////////////////////////////////////
49+
// EXECUTION
50+
//////////////////////////////////////////////////////////////////////
51+
52+
RunTarget(target);

build/build.ps1

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
##########################################################################
2+
# This is the Cake bootstrapper script for PowerShell.
3+
# This file was downloaded from https://github.com/cake-build/resources
4+
# Feel free to change this file to fit your needs.
5+
##########################################################################
6+
7+
<#
8+
9+
.SYNOPSIS
10+
This is a Powershell script to bootstrap a Cake build.
11+
12+
.DESCRIPTION
13+
This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
14+
and execute your Cake build script with the parameters you provide.
15+
16+
.PARAMETER Script
17+
The build script to execute.
18+
.PARAMETER Target
19+
The build script target to run.
20+
.PARAMETER Configuration
21+
The build configuration to use.
22+
.PARAMETER Verbosity
23+
Specifies the amount of information to be displayed.
24+
.PARAMETER Experimental
25+
Tells Cake to use the latest Roslyn release.
26+
.PARAMETER WhatIf
27+
Performs a dry run of the build script.
28+
No tasks will be executed.
29+
.PARAMETER Mono
30+
Tells Cake to use the Mono scripting engine.
31+
.PARAMETER SkipToolPackageRestore
32+
Skips restoring of packages.
33+
.PARAMETER ScriptArgs
34+
Remaining arguments are added here.
35+
36+
.LINK
37+
http://cakebuild.net
38+
39+
#>
40+
41+
[CmdletBinding()]
42+
Param(
43+
[string]$Script = "build.cake",
44+
[string]$Target = "Default",
45+
[ValidateSet("Release", "Debug")]
46+
[string]$Configuration = "Release",
47+
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
48+
[string]$Verbosity = "Verbose",
49+
[switch]$Experimental,
50+
[Alias("DryRun","Noop")]
51+
[switch]$WhatIf,
52+
[switch]$Mono,
53+
[switch]$SkipToolPackageRestore,
54+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
55+
[string[]]$ScriptArgs
56+
)
57+
58+
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
59+
function MD5HashFile([string] $filePath)
60+
{
61+
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
62+
{
63+
return $null
64+
}
65+
66+
[System.IO.Stream] $file = $null;
67+
[System.Security.Cryptography.MD5] $md5 = $null;
68+
try
69+
{
70+
$md5 = [System.Security.Cryptography.MD5]::Create()
71+
$file = [System.IO.File]::OpenRead($filePath)
72+
return [System.BitConverter]::ToString($md5.ComputeHash($file))
73+
}
74+
finally
75+
{
76+
if ($file -ne $null)
77+
{
78+
$file.Dispose()
79+
}
80+
}
81+
}
82+
83+
Write-Host "Preparing to run build script..."
84+
85+
if(!$PSScriptRoot){
86+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
87+
}
88+
89+
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
90+
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
91+
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
92+
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
93+
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
94+
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
95+
96+
# Should we use mono?
97+
$UseMono = "";
98+
if($Mono.IsPresent) {
99+
Write-Verbose -Message "Using the Mono based scripting engine."
100+
$UseMono = "-mono"
101+
}
102+
103+
# Should we use the new Roslyn?
104+
$UseExperimental = "";
105+
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
106+
Write-Verbose -Message "Using experimental version of Roslyn."
107+
$UseExperimental = "-experimental"
108+
}
109+
110+
# Is this a dry run?
111+
$UseDryRun = "";
112+
if($WhatIf.IsPresent) {
113+
$UseDryRun = "-dryrun"
114+
}
115+
116+
# Make sure tools folder exists
117+
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
118+
Write-Verbose -Message "Creating tools directory..."
119+
New-Item -Path $TOOLS_DIR -Type directory | out-null
120+
}
121+
122+
# Make sure that packages.config exist.
123+
if (!(Test-Path $PACKAGES_CONFIG)) {
124+
Write-Verbose -Message "Downloading packages.config..."
125+
try { (New-Object System.Net.WebClient).DownloadFile("http://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
126+
Throw "Could not download packages.config."
127+
}
128+
}
129+
130+
# Try find NuGet.exe in path if not exists
131+
if (!(Test-Path $NUGET_EXE)) {
132+
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
133+
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }
134+
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
135+
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
136+
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
137+
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
138+
}
139+
}
140+
141+
# Try download NuGet.exe if not exists
142+
if (!(Test-Path $NUGET_EXE)) {
143+
Write-Verbose -Message "Downloading NuGet.exe..."
144+
try {
145+
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
146+
} catch {
147+
Throw "Could not download NuGet.exe."
148+
}
149+
}
150+
151+
# Save nuget.exe path to environment to be available to child processed
152+
$ENV:NUGET_EXE = $NUGET_EXE
153+
154+
# Restore tools from NuGet?
155+
if(-Not $SkipToolPackageRestore.IsPresent) {
156+
Push-Location
157+
Set-Location $TOOLS_DIR
158+
159+
# Check for changes in packages.config and remove installed tools if true.
160+
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
161+
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
162+
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
163+
Write-Verbose -Message "Missing or changed package.config hash..."
164+
Remove-Item * -Recurse -Exclude packages.config,nuget.exe
165+
}
166+
167+
Write-Verbose -Message "Restoring tools from NuGet..."
168+
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
169+
170+
if ($LASTEXITCODE -ne 0) {
171+
Throw "An error occured while restoring NuGet tools."
172+
}
173+
else
174+
{
175+
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
176+
}
177+
Write-Verbose -Message ($NuGetOutput | out-string)
178+
Pop-Location
179+
}
180+
181+
# Make sure that Cake has been installed.
182+
if (!(Test-Path $CAKE_EXE)) {
183+
Throw "Could not find Cake.exe at $CAKE_EXE"
184+
}
185+
186+
# Start Cake
187+
Write-Host "Running build script..."
188+
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
189+
exit $LASTEXITCODE

build/tools/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Cake" version="0.17.0" />
4+
</packages>

src/SimpleEventStore/SimpleEventStore.AzureDocumentDb.Tests/SimpleEventStore.AzureDocumentDb.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
43
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
54
<PropertyGroup>
65
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -97,7 +96,6 @@
9796
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
9897
</PropertyGroup>
9998
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.11.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.11.1\build\Microsoft.Azure.DocumentDB.targets'))" />
100-
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
10199
</Target>
102100
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
103101
Other similar extension points exist, see Microsoft.Common.targets.

src/SimpleEventStore/SimpleEventStore.AzureDocumentDb.Tests/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
<package id="xunit.core" version="2.1.0" targetFramework="net461" />
99
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net461" />
1010
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net461" />
11-
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net461" />
1211
</packages>

src/SimpleEventStore/SimpleEventStore.Tests/SimpleEventStore.Tests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
43
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
54
<PropertyGroup>
65
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -85,12 +84,6 @@
8584
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
8685
</ItemGroup>
8786
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
88-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
89-
<PropertyGroup>
90-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
91-
</PropertyGroup>
92-
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
93-
</Target>
9487
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9588
Other similar extension points exist, see Microsoft.Common.targets.
9689
<Target Name="BeforeBuild">

src/SimpleEventStore/SimpleEventStore.Tests/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
<package id="xunit.core" version="2.1.0" targetFramework="net461" />
77
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net461" />
88
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net461" />
9-
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net461" />
109
</packages>

0 commit comments

Comments
 (0)