Skip to content

Commit

Permalink
Provide with options in build.cmd (dotnet#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
qinezh authored Jun 28, 2016
1 parent 5353340 commit 7edcc4e
Showing 1 changed file with 71 additions and 28 deletions.
99 changes: 71 additions & 28 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,95 @@ PUSHD %~dp0
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION

:Loop
if [%1]==[] GOTO Begin

if /I [%1]==[Debug] (
SET Configuration=%1
GOTO Next
)

if /I [%1]==[Release] (
SET Configuration=%1
GOTO Next
)

if /I [%1]==[PROD] (
SET Environment=PROD
GOTO Next
)

if /I [%1]==[raw] (
SET SkipTemplate=true
GOTO Next
)
if /I [%1]==[template] (
SET UpdateTemplate=%1
GOTO Next
)

:Next
SHIFT /1
GOTO Loop

:Begin
IF NOT DEFINED VisualStudioVersion (
IF DEFINED VS140COMNTOOLS (
CALL "%VS140COMNTOOLS%\VsDevCmd.bat"
GOTO :EnvSet
GOTO EnvSet
)

ECHO Error: build.cmd requires Visual Studio 2015.
SET ERRORLEVEL=1
GOTO :Exit
GOTO Exit
)

:EnvSet
SET BuildProj=%~dp0All.sln
SET Configuration=%1
IF '%Configuration%'=='' (
IF [%Configuration%]==[] (
SET Configuration=Release
)
SET Environment=%2
IF '%Environment%'=='PROD' (
IF /I [%Environment%]==[PROD] (
ECHO Updating version for PROD environment
CALL UpdateVersion.cmd

IF NOT '!ERRORLEVEL!'=='0' (
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: Error occurs when updating version
GOTO :Exit
GOTO Exit
)
)

:: Check if DNU exists globally
:: DNU is OPTIONAL
WHERE dnu >NUL
IF NOT '%ERRORLEVEL%'=='0' (
ECHO ERROR: DNU is not successfully configured.
ECHO ERROR: Please follow http://docs.asp.net/en/latest/getting-started/installing-on-windows.html#install-the-net-version-manager-dnvm to install dnvm.
ECHO ERROR: If dnvm is installed, use `dnvm list` to show available dnx runtime, and use `dnvm use` to select the default dnx runtime
GOTO :Exit
IF /I [%UpdateTemplate%]==[template] (
ECHO Updating template
CALL UpdateTemplate.cmd
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: Error occurs when updating template
)
GOTO Exit
)
IF /I [%SkipTemplate%]==[true] (
ECHO Skip updating template
GOTO CheckDnu
)

:: Update template before build
:UpdateTemplate
ECHO Updating template
CALL UpdateTemplate.cmd

IF NOT '!ERRORLEVEL!'=='0' (
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: Error occurs when updating template
GOTO :Exit
GOTO Exit
)

:: Check if DNU exists globally
:: DNU is OPTIONAL
:CheckDnu
WHERE dnu >NUL
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: DNU is not successfully configured.
ECHO ERROR: Please follow http://docs.asp.net/en/latest/getting-started/installing-on-windows.html#install-the-net-version-manager-dnvm to install dnvm.
ECHO ERROR: If dnvm is installed, use `dnvm list` to show available dnx runtime, and use `dnvm use` to select the default dnx runtime
GOTO Exit
)

:: Restore packages for .csproj projects
Expand All @@ -67,8 +111,8 @@ SET BuildPrefix=
SET BuildPostfix=
CALL :Build %*

IF NOT '%ErrorLevel%'=='0' (
GOTO :AfterBuild
IF NOT [!ERRORLEVEL!]==[0] (
GOTO AfterBuild
)

POPD
Expand All @@ -88,7 +132,7 @@ findstr /ir /c:"Total:.*Failed.*Skipped.*Time.*" "%BuildLog%" & cd >nul
ECHO Exit Code: %BuildErrorLevel%
SET ERRORLEVEL=%BuildErrorLevel%

GOTO :Exit
GOTO Exit

:Build
%BuildPrefix% msbuild "%BuildProj%" /p:Configuration=%Configuration% /nologo /maxcpucount:1 /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=d;LogFile="%BuildLog%"; %BuildPostfix%
Expand All @@ -107,22 +151,21 @@ FOR /D %%x IN ("src","test","tools") DO (
:RestoreNormalPackage
:: Currently version 3.3 is not compatible with our build, force to use v2.8.6
SET CachedNuget=%LocalAppData%\NuGet\v2.8.6\NuGet.exe
IF EXIST "%CachedNuget%" GOTO :Restore
IF EXIST "%CachedNuget%" GOTO Restore
ECHO Downloading NuGet.exe v2.8.6...
IF NOT EXIST "%LocalAppData%\NuGet\v2.8.6" MD "%LocalAppData%\NuGet\v2.8.6"
powershell -NoProfile -ExecutionPolicy UnRestricted -Command "$ProgressPreference = 'SilentlyContinue'; [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/v2.8.6/nuget.exe' -OutFile '%CachedNuget%'"

IF NOT '%ErrorLevel%'=='0' (
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: Failed downloading NuGet.exe
GOTO :Exit
GOTO Exit
)

:Restore
%CachedNuget% restore "%BuildProj%"

IF NOT '%ErrorLevel%'=='0' (
IF NOT [!ERRORLEVEL!]==[0] (
ECHO ERROR: Error when restoring packages for %BuildProj%
GOTO :Exit
GOTO Exit
)

:Exit
Expand Down

0 comments on commit 7edcc4e

Please sign in to comment.