From f174b0bef9873a8f2ece2d0e2cf2d3a730a52ea6 Mon Sep 17 00:00:00 2001 From: Matthew King Date: Wed, 4 Jul 2018 21:23:33 +0800 Subject: [PATCH] Add build scripts. --- .gitignore | 29 +++++------------------------ build/build.cmd | 2 ++ build/build.ps1 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 build/build.cmd create mode 100644 build/build.ps1 diff --git a/.gitignore b/.gitignore index dd92dfd..3f6d495 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,6 @@ -# build folders -[Bb]in/ -[Oo]bj/ - -# build results -[Dd]ebug/ -[Rr]elease/ - -# user-specific files .vs/ -*.suo -*.user -*.sln.docstates - -# ncrunch -*.crunchsolution* -*.ncrunchsolution* -*.ncrunchproject* - -# nuget -packages/ - -# other -*.[Cc]ache -project.lock.json +.vscode/ +bin/ +obj/ +build/tools/ +artifacts/ diff --git a/build/build.cmd b/build/build.cmd new file mode 100644 index 0000000..edad89a --- /dev/null +++ b/build/build.cmd @@ -0,0 +1,2 @@ +@echo off +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0\build.ps1" diff --git a/build/build.ps1 b/build/build.ps1 new file mode 100644 index 0000000..7f3115b --- /dev/null +++ b/build/build.ps1 @@ -0,0 +1,44 @@ +# Get the root project directory. +$root = Resolve-Path (Join-Path $PSScriptRoot '..') + +# Set up the tools directory. +$toolsDir = "$root\build\tools" +if ((Test-Path -path $toolsDir) -eq $false) { + New-Item $toolsDir -Type Directory | Out-Null +} + +# Set up the output directory. +$outputDir = "$root\artifacts" +if ((Test-Path -path $outputDir) -eq $false) { + New-Item $outputDir -Type Directory | Out-Null +} + +# Find or download NuGet. +$nuget = "$toolsDir\nuget.exe" +if ((Test-Path $nuget) -eq $false) { + Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nuget +} + +# Find or download VSWhere. +$vswhere = "$toolsDir\vswhere\tools\vswhere.exe" +if ((Test-Path $vswhere) -eq $false) { + & $nuget install vswhere -ExcludeVersion -OutputDirectory $toolsDir +} + +# Find VS using VSWhere +$vs = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath +if ((Test-Path $vs) -eq $false) { + throw 'Could not find VS installation' +} + +# Locate MSBuild using resolved VS path. +$msbuild = Resolve-Path "$vs\MSBuild\*\Bin\MSBuild.exe" +if ((Test-Path $msbuild) -eq $false) { + throw 'Could not find MSBuild' +} + +# Set MSBuild alias. +Set-Alias MSBuild $msbuild + +# Build and pack. +MSBuild "/t:Restore;Build;Pack" "/p:Configuration=Release,OutputPath=$outputDir" "$root\src\NGuard\NGuard.csproj"