Skip to content

Commit dc05b64

Browse files
Merge pull request #71 from neutmute/build
command line build scripts
2 parents 58f84db + 68ae10c commit dc05b64

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

build.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
powershell -f build.ps1 -configuration release
2+
powershell -f build.ps1 -configuration debug

build.common.ps1

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
$Script:UseWriteHost = $true
2+
3+
if(!$Global:ColorScheme) {
4+
$Global:ColorScheme = @{
5+
"Banner"=[ConsoleColor]::Cyan
6+
"RuntimeName"=[ConsoleColor]::Yellow
7+
"Help_Header"=[ConsoleColor]::Yellow
8+
"Help_Switch"=[ConsoleColor]::Green
9+
"Help_Argument"=[ConsoleColor]::Cyan
10+
"Help_Optional"=[ConsoleColor]::Gray
11+
"Help_Command"=[ConsoleColor]::DarkYellow
12+
"Help_Executable"=[ConsoleColor]::DarkYellow
13+
"ParameterName"=[ConsoleColor]::Cyan
14+
"Warning" = [ConsoleColor]::Yellow
15+
}
16+
}
17+
18+
function _WriteOut {
19+
param(
20+
[Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true)][string]$msg,
21+
[Parameter(Mandatory=$false)][ConsoleColor]$ForegroundColor,
22+
[Parameter(Mandatory=$false)][ConsoleColor]$BackgroundColor,
23+
[Parameter(Mandatory=$false)][switch]$NoNewLine)
24+
25+
if($__TestWriteTo) {
26+
$cur = Get-Variable -Name $__TestWriteTo -ValueOnly -Scope Global -ErrorAction SilentlyContinue
27+
$val = $cur + "$msg"
28+
if(!$NoNewLine) {
29+
$val += [Environment]::NewLine
30+
}
31+
Set-Variable -Name $__TestWriteTo -Value $val -Scope Global -Force
32+
return
33+
}
34+
35+
if(!$Script:UseWriteHost) {
36+
if(!$msg) {
37+
$msg = ""
38+
}
39+
if($NoNewLine) {
40+
[Console]::Write($msg)
41+
} else {
42+
[Console]::WriteLine($msg)
43+
}
44+
}
45+
else {
46+
try {
47+
if(!$ForegroundColor) {
48+
$ForegroundColor = $host.UI.RawUI.ForegroundColor
49+
}
50+
if(!$BackgroundColor) {
51+
$BackgroundColor = $host.UI.RawUI.BackgroundColor
52+
}
53+
54+
Write-Host $msg -ForegroundColor:$ForegroundColor -BackgroundColor:$BackgroundColor -NoNewLine:$NoNewLine
55+
} catch {
56+
$Script:UseWriteHost = $false
57+
_WriteOut $msg
58+
}
59+
}
60+
}
61+
62+
function _WriteConfig{
63+
param(
64+
[Parameter(Mandatory=$true,Position=0)]$name,
65+
[Parameter(Mandatory=$true,Position=1)]$value)
66+
67+
_WriteOut -NoNewline -ForegroundColor $Global:ColorScheme.ParameterName "${name}: "
68+
_WriteOut "$value"
69+
70+
}
71+
72+
function _DownloadNuget{
73+
param(
74+
[Parameter(Mandatory=$true,Position=0)]$rootPath)
75+
76+
$sourceNugetExe = "http://nuget.org/nuget.exe"
77+
$targetNugetExe = "$rootPath\nuget.exe"
78+
79+
80+
if(!(Test-Path $targetNugetExe )){
81+
_WriteOut "Downloading nuget to $targetNugetExe"
82+
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
83+
}
84+
else{
85+
# _WriteOut "nuget.exe is already present"
86+
}
87+
88+
Set-Alias nuget $targetNugetExe -Scope Global
89+
90+
}

build.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
param(
2+
[string]$configuration = "Release"
3+
)
4+
5+
. ".\build.common.ps1"
6+
7+
$solutionName = "RaspberrySharp.IO"
8+
9+
function init {
10+
# Initialization
11+
$global:rootFolder = Split-Path -parent $script:MyInvocation.MyCommand.Path
12+
$global:rootFolder = Join-Path $rootFolder .
13+
$global:packagesFolder = Join-Path $rootFolder packages
14+
$global:outputFolder = Join-Path $rootFolder _artifacts
15+
$global:msbuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
16+
17+
_WriteOut -ForegroundColor $ColorScheme.Banner "-= $solutionName Build =-"
18+
_WriteConfig "rootFolder" $rootFolder
19+
}
20+
21+
function restorePackages{
22+
_WriteOut -ForegroundColor $ColorScheme.Banner "nuget restore"
23+
24+
New-Item -Force -ItemType directory -Path $packagesFolder
25+
_DownloadNuget $packagesFolder
26+
nuget restore
27+
}
28+
29+
function buildSolution{
30+
31+
_WriteOut -ForegroundColor $ColorScheme.Banner "Build Solution"
32+
& $msbuild "$rootFolder\$solutionName.sln" /p:Configuration=$configuration
33+
34+
}
35+
36+
37+
init
38+
39+
restorePackages
40+
41+
buildSolution
42+
43+
Write-Host "Build $configuration complete"

0 commit comments

Comments
 (0)