Skip to content

Commit 20fd7bc

Browse files
Update ASP.NET build scripts
1 parent 992060b commit 20fd7bc

File tree

3 files changed

+109
-77
lines changed

3 files changed

+109
-77
lines changed

build.cmd

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,2 @@
1-
@echo off
2-
cd %~dp0
3-
4-
SETLOCAL
5-
SET NUGET_VERSION=latest
6-
SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe
7-
SET BUILDCMD_KOREBUILD_VERSION=
8-
SET BUILDCMD_DNX_VERSION=
9-
10-
IF EXIST %CACHED_NUGET% goto copynuget
11-
echo Downloading latest version of NuGet.exe...
12-
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
13-
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"
14-
15-
:copynuget
16-
IF EXIST .nuget\nuget.exe goto restore
17-
md .nuget
18-
copy %CACHED_NUGET% .nuget\nuget.exe > nul
19-
20-
:restore
21-
IF EXIST packages\Sake goto getdnx
22-
IF "%BUILDCMD_KOREBUILD_VERSION%"=="" (
23-
.nuget\nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
24-
) ELSE (
25-
.nuget\nuget.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
26-
)
27-
.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages
28-
29-
:getdnx
30-
IF "%BUILDCMD_DNX_VERSION%"=="" (
31-
SET BUILDCMD_DNX_VERSION=latest
32-
)
33-
IF "%SKIP_DNX_INSTALL%"=="" (
34-
CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CoreCLR -arch x86 -alias default
35-
CALL packages\KoreBuild\build\dnvm install default -runtime CLR -arch x86 -alias default
36-
) ELSE (
37-
CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
38-
)
39-
40-
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
1+
@ECHO OFF
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"

build.ps1

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries)
4+
{
5+
while($true)
6+
{
7+
try
8+
{
9+
Invoke-WebRequest $url -OutFile $downloadLocation
10+
break
11+
}
12+
catch
13+
{
14+
$exceptionMessage = $_.Exception.Message
15+
Write-Host "Failed to download '$url': $exceptionMessage"
16+
if ($retries -gt 0) {
17+
$retries--
18+
Write-Host "Waiting 10 seconds before retrying. Retries left: $retries"
19+
Start-Sleep -Seconds 10
20+
21+
}
22+
else
23+
{
24+
$exception = $_.Exception
25+
throw $exception
26+
}
27+
}
28+
}
29+
}
30+
31+
cd $PSScriptRoot
32+
33+
$repoFolder = $PSScriptRoot
34+
$env:REPO_FOLDER = $repoFolder
35+
36+
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
37+
if ($env:KOREBUILD_ZIP)
38+
{
39+
$koreBuildZip=$env:KOREBUILD_ZIP
40+
}
41+
42+
$buildFolder = ".build"
43+
$buildFile="$buildFolder\KoreBuild.ps1"
44+
45+
if (!(Test-Path $buildFolder)) {
46+
Write-Host "Downloading KoreBuild from $koreBuildZip"
47+
48+
$tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid()
49+
New-Item -Path "$tempFolder" -Type directory | Out-Null
50+
51+
$localZipFile="$tempFolder\korebuild.zip"
52+
53+
DownloadWithRetry -url $koreBuildZip -downloadLocation $localZipFile -retries 6
54+
55+
Add-Type -AssemblyName System.IO.Compression.FileSystem
56+
[System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder)
57+
58+
New-Item -Path "$buildFolder" -Type directory | Out-Null
59+
copy-item "$tempFolder\**\build\*" $buildFolder -Recurse
60+
61+
# Cleanup
62+
if (Test-Path $tempFolder) {
63+
Remove-Item -Recurse -Force $tempFolder
64+
}
65+
}
66+
67+
&"$buildFile" $args

build.sh

+40-37
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
#!/usr/bin/env bash
2+
repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
cd $repoFolder
24

3-
if test `uname` = Darwin; then
4-
cachedir=~/Library/Caches/KBuild
5-
else
6-
if [ -z $XDG_DATA_HOME ]; then
7-
cachedir=$HOME/.local/share
8-
else
9-
cachedir=$XDG_DATA_HOME;
10-
fi
11-
fi
12-
mkdir -p $cachedir
13-
nugetVersion=latest
14-
cachePath=$cachedir/nuget.$nugetVersion.exe
15-
16-
url=https://dist.nuget.org/win-x86-commandline/$nugetVersion/nuget.exe
17-
18-
if test ! -f $cachePath; then
19-
wget -O $cachePath $url 2>/dev/null || curl -o $cachePath --location $url /dev/null
20-
fi
21-
22-
if test ! -e .nuget; then
23-
mkdir .nuget
24-
cp $cachePath .nuget/nuget.exe
5+
koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
6+
if [ ! -z $KOREBUILD_ZIP ]; then
7+
koreBuildZip=$KOREBUILD_ZIP
258
fi
269

27-
if test ! -d packages/Sake; then
28-
mono .nuget/nuget.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
29-
mono .nuget/nuget.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages
30-
fi
31-
32-
if ! type dnvm > /dev/null 2>&1; then
33-
source packages/KoreBuild/build/dnvm.sh
34-
fi
35-
36-
if ! type dnx > /dev/null 2>&1 || [ -z "$SKIP_DNX_INSTALL" ]; then
37-
dnvm install latest -runtime coreclr -alias default
38-
dnvm install default -runtime mono -alias default
39-
else
40-
dnvm use default -runtime mono
10+
buildFolder=".build"
11+
buildFile="$buildFolder/KoreBuild.sh"
12+
13+
if test ! -d $buildFolder; then
14+
echo "Downloading KoreBuild from $koreBuildZip"
15+
16+
tempFolder="/tmp/KoreBuild-$(uuidgen)"
17+
mkdir $tempFolder
18+
19+
localZipFile="$tempFolder/korebuild.zip"
20+
21+
retries=6
22+
until (wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip 2>/dev/null)
23+
do
24+
echo "Failed to download '$koreBuildZip'"
25+
if [ "$retries" -le 0 ]; then
26+
exit 1
27+
fi
28+
retries=$((retries - 1))
29+
echo "Waiting 10 seconds before retrying. Retries left: $retries"
30+
sleep 10s
31+
done
32+
33+
unzip -q -d $tempFolder $localZipFile
34+
35+
mkdir $buildFolder
36+
cp -r $tempFolder/**/build/** $buildFolder
37+
38+
chmod +x $buildFile
39+
40+
# Cleanup
41+
if test ! -d $tempFolder; then
42+
rm -rf $tempFolder
43+
fi
4144
fi
4245

43-
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
46+
$buildFile -r $repoFolder "$@"

0 commit comments

Comments
 (0)