Build ASP.NET Core 1.0 with TFS 2013.4 Build Server
To build ASP.NET Core 1.0 with Team Foundation 2013.4 XAML builds, the following steps should be done.
Prepare the build server
- Install VS 2015 on the build server
- Install below by logging into the build server as build service user (tfsbuildsvc in this case). Install chocolatey on the build server (it's easy to do other installations when chocolatey is installed.)
- To install chocolatey, run below command in PS window (run as administrator):
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
- Install NodeJS with below command:
choco install nodejs.install
- Change directory to NodeJS install path (C:\Program Files\nodejs)
- Install Bower and Gulp for global use using below commands:
npm install bower -g
npm install gulp -g
**
Build Scripts
Pre-Build
Pre-build script to set DNX is required. Use below script.
# bootstrap DNVM into this session.
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
# load up the global.json so we can find the DNX version
$globalJson = Get-Content -Path $PSScriptRoot\..\..\MainSolution\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
if($globalJson)
{
$dnxVersion = $globalJson.sdk.version
}
else
{
Write-Warning "Unable to locate global.json to determine using 'latest'"
$dnxVersion = "latest"
}
# install DNX
# only installs the default (x86, clr) runtime of the framework.
# If you need additional architectures or runtimes you should add additional calls
# ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
# run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $PSScriptRoot\..\..\MainSolution -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }
dnvm upgrade -r clr
* *Post-Build Publish Script
In publish script environment, variable settings to path should be added below. This will allow you to run Pre-Publish script specified in project.json
$env:Path += ";C:\Program Files\nodejs;C:\Users\tfsbuildsvc\AppData\Roaming\npm"
https://lh3.googleusercontent.com/-t5Rao_3NCEM/VymNKgRWJYI/AAAAAAAAHDA/fwWWNGEDv0Y/image_thumb%25255B9%25255D.png?imgmax=800
param($solutionName, $projectName, $projectPath, $buildConfiguration, $buildStagingDirectory)
$VerbosePreference = "continue"
$ErrorActionPreference = "stop"
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
$globalJson = Get-Content -Path "$PSScriptRoot\..\..\$solutionName\global.json" -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
if($globalJson)
{
$dnxVersion = $globalJson.sdk.version
}
else
{
Write-Warning "Unable to locate global.json to determine using 'latest'"
$dnxVersion = "latest"
}
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent
$dnxRuntimePath = "$($env:USERPROFILE)\.dnx\runtimes\dnx-clr-win-x86.$dnxVersion"
#& "dnu" "build" "$PSScriptRoot\src\$projectPath" "--configuration" "$buildConfiguration"
Write-Warning "Path is $PSScriptRoot\..\..\$projectPath"
$env:Path += ";C:\Program Files\nodejs;C:\Users\tfs10buildsvc\AppData\Roaming\npm"
$publichLocation = "$buildStagingDirectory\$projectName"
[IO.Directory]::CreateDirectory($publichLocation)
& "dnu" "publish" "$PSScriptRoot\..\..\$projectPath" "--configuration" "$buildConfiguration" "--out" "$publichLocation" "--runtime" "$dnxRuntimePath"
Check-in Build Scripts
Scripts are in below folder structure. Path changes ($PSScriptRoot\.\.\ to script required if it is checked into different folder hierarchy.
https://lh3.googleusercontent.com/-I7IFt7IUz0w/VymNM5XHS3I/AAAAAAAAHDI/VRSXXlIPy6A/image_thumb%25255B2%25255D.png?imgmax=800
Set Build definition to Run Build scripts
In build definition, set to execute scripts as shown below. Set tool version in build definition to use VS 2015 tools. /tv:14https://lh3.googleusercontent.com/-HJQU6G1KXqA/VymNPs2bCXI/AAAAAAAAHDQ/GNXA301C0bs/image_thumb%25255B16%25255D.png?imgmax=800
RunPreBuildScript.ps1
Invoke-Expression "$PSScriptRoot\SetDNX.ps1"
RunPostBuildScript.ps1
param($buildConfiguration)
Invoke-Expression "$PSScriptRoot\PublishWebSite.ps1 -solutionName MainSolution -projectName WebPortal -projectPath 'MainSolution\WebPortal' -buildConfiguration $buildConfiguration -buildStagingDirectory $Env:TF_BUILD_BINARIESDIRECTORY"
RunPreBuildScript and RunPostBuildScript are used since there could be more scripts that need to be executed and only one is allowed in XAML build definition. These scripts could invoke other scripts.
You could run into
npm WARN deprecated graceful-fs@3.0.8: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated npmconf@2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
npm ERR! cb() never called!
npm ERR! not ok code 0
https://lh3.googleusercontent.com/-z-0ez2MbSeE/VymNSLpbvrI/AAAAAAAAHDY/aw420UkdeW0/image_thumb%25255B5%25255D.png?imgmax=800
This is discussed in here. To disable this warning raising as an error, change the project.json pre-publish script section as below (Add --loglevel=error to npm install).https://lh3.googleusercontent.com/-xoDp0YXzz5E/VymNUTjPhQI/AAAAAAAAHDg/-S4ejyvquGo/image_thumb%25255B12%25255D.png?imgmax=800
You can get a successful build with TFS build 2013.4, for ASP.NET Core 1.0.https://lh3.googleusercontent.com/-XVYc-xCtZws/VymNW7-gL7I/AAAAAAAAHDo/SNrZoXu-gOU/image_thumb%25255B19%25255D.png?imgmax=800
https://lh3.googleusercontent.com/-TdO7GNm_Mss/VymNY9eKO9I/AAAAAAAAHDw/mfmiM8Bs0zQ/image_thumb%25255B22%25255D.png?imgmax=800