2015 Ignite New Zealand demo prep: Step 5

Steps:

  1. Intro
  2. VSO
  3. Docker
  4. xUnit
  5. Build
  6. Back end
  7. Selenium
  8. Docker
  9. Release Management
  10. Testing

While preparing this post, I realized I had not shown the entire system of what we are trying to assemble. Below is an image of what we are building.

Our next goal is to begin creating our build definition in Visual Studio Online (VSO).  Because ASP.NET 5 is still in preview, our build machines require some additional steps to be able to build ASP.NET 5 projects.  We perform those steps via PowerShell. In this post, we will create the required PowerShell and configure our build.

To build an ASP.NET 5 project, you must have a .NET Execution Environment (DNX).  The DNX is an SDK and runtime environment that enables you to build and run .NET applications on Windows, Mac, and Linux.  By default, this will not be on build agents, so we are going to create a PowerShell script that will install it for us.  Very similarly to build, testing an ASP.NET 5 application requires special care.  We are going to employ a second PowerShell script to execute our tests.

  1. Add Install_DNX.ps1 file to your Solutions Items Folder
    1. Open Solutions Explorer in Visual Studio
    2. Right-click on the Solutions Items folder
    3. Select Add / New Item…
    4. Add a new text file and name it Install_DNX.ps1
  2. Copy and paste the code below into the file

    # 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\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 -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

  3. Add RunTests.ps1 file to your Solutions Items Folder
    1. Open Solutions Explorer in Visual Studio
    2. Right-click on the Solutions Items folder
    3. Select Add / New Item…
    4. Add a new text file and name it RunTests.ps1
  4. Copy and paste the code below into the file

    Set-ExecutionPolicy unrestricted -Scope CurrentUser -Force

    # Setup the dnx and add it to your current path
    dnvm setup

    # Set runtime to use
    dnvm use 1.0.0-beta7

    # Run the test
    dnx test

  5. Commit and Push our changes to VSO

    With all the files in place, we can begin creating our build.

  6. Create new Visual Studio Build
    1. Visit the Build hub of your VSO project
    2. Click the Actions link
    3. Select the Visual Studio build template
    4. Click Next
    5. Change Default agent queue to Default
    6. Check the check box for Continuous Integration
    7. Click Create
  7. Add PowerShell step to top of build to run Install_DNX.ps1
    1. Click + Add Build step…
    2. Select PowerShell from the Utility section
    3. Drag and drop this step from the bottom to the top of the list of steps
    4. Click the browse button for the Script filename
    5. Select the Install_DNX.ps1 file

    This will ensure our build agent has everything it needs to be able to build our code.  Now we need to repeat this process to run our tests.

  8. Add PowerShell step after Visual Studio Test step to run RunTests.ps1 with a working directory of your test project
    1. Click + Add Build step…
    2. Select PowerShell from the Utility section
    3. Drag and drop this step under the Visual Studio Test step
    4. Click the browse button for the Script filename
    5. Select the RunTests.ps1 file
    6. Expand the Advanced section
    7. Click the browse button for the Working folder
    8. Select the folder of your test project
  9. Add a task to publish the test results
    1. Click + Add Build step…
    2. Select Publish Test Results from the Test section
    3. Drag and drop this step from the bottom to under the PowerShell step we added to run the tests
    4. Set the Test Result Format to Xunit
  10. Set the build configuration to Release
    1. Click the Variables tab
    2. Change debug to release for the BuildConfiguration variable
  11. Save your build
    1. Click Save
    2. Give your build a name
    3. Click OK
  12. Queue a build
    1. Click Queue build...
    2. Click OK

Do not be alarmed by the “No test assemblies found” warning.  That will go away once we add the Web API to access our SQL Azure Database in future posts.

Pingbacks and trackbacks (20)+

Add comment

Loading