Created
July 21, 2016 12:19
-
-
Save forcewake/d3a66afe2d6dd67e5fae84a835f97570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$TestsRegex = '\.Tests$' | |
$dotnetCliUrl = 'https://go.microsoft.com/fwlink/?LinkID=798402' | |
if (Test-Path '.dotnet-cli/dotnet.exe') { | |
$dotnet = '.dotnet-cli/dotnet.exe' | |
} | |
else { | |
$dotnet = 'dotnet.exe' | |
} | |
function ExtractZip($srcZip, $destDir) { | |
Add-Type -Assembly "System.IO.Compression.FileSystem" | |
[IO.Compression.ZipFile]::ExtractToDirectory($srcZip, $destDir) | |
} | |
function AllProjects() { | |
Get-ChildItem */project.json | |
} | |
function PackageProjects() { | |
AllProjects | Where {$_.Directory.Name -notmatch $TestsRegex} | |
} | |
function TestProjects() { | |
AllProjects | Where {$_.Directory.Name -match $TestsRegex} | |
} | |
function CleanCmd() { | |
AllProjects | %{$_.Directory} | %{ | |
if (Test-Path $_/bin) {Remove-Item -Recurse $_/bin} | |
if (Test-Path $_/obj) {Remove-Item -Recurse $_/obj} | |
} | |
if (Test-Path artifacts) {Remove-Item -Recurse artifacts} | |
} | |
function EnsureDotnetCliCmd() { | |
if (!(Test-Path '.dotnet-cli/dotnet.exe')) | |
{ | |
Invoke-WebRequest $dotnetCliUrl -OutFile 'dotnet-cli.zip' | |
ExtractZip 'dotnet-cli.zip' "$pwd/.dotnet-cli" | |
$dotnet = '.dotnet-cli/dotnet.exe' | |
} | |
} | |
function InstallCmd() { | |
& $dotnet restore | |
} | |
function BuildCmd() { | |
Write-Host "Building projects:" | |
PackageProjects | %{Write-Host " $_"} | |
if ($env:BUILD_BUILDNUMBER) { | |
$env:DOTNET_BUILD_VERSION = $env:BUILD_BUILDNUMBER | |
} | |
else { | |
$env:DOTNET_BUILD_VERSION = 'z' | |
} | |
PackageProjects | %{ | |
Write-Host "Building $_" | |
& $dotnet pack $_.Directory -c Release | |
} | |
} | |
function TestCmd() { | |
$codes = (TestProjects) | %{& $dotnet test $_ | Write-Host; $LASTEXITCODE} | |
$code = ($codes | Measure-Object -Sum).Sum | |
exit $code | |
} | |
function RegisterCmd() { | |
PackageProjects | %{ | |
Get-ChildItem -Recurse *.nupkg | %{ | |
nuget add $_ -Source "$env:USERPROFILE/.nuget/packages" | |
} | |
} | |
} | |
function RunCommand($name) { | |
switch ($name) { | |
ensurecli {EnsureDotnetCliCmd} | |
clean {CleanCmd} | |
install {InstallCmd} | |
build {BuildCmd} | |
test {TestCmd} | |
register {RegisterCmd} | |
all {CleanCmd; InstallCmd; BuildCmd; RegisterCmd} | |
} | |
} | |
$args | %{RunCommand $_} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<packageSources> | |
<add | |
key="nuget.org" | |
value="https://api.nuget.org/v3/index.json" | |
protocolVersion="3" /> | |
<add | |
key="sharper-c" | |
value="https://www.myget.org/F/sharper-c/api/v3/index.json" | |
protocolVersion="3" /> | |
<add | |
key="xunit" | |
value="https://www.myget.org/F/xunit/api/v3/index.json" | |
protocolVersion="3" /> | |
</packageSources> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment