Build your ASP.NET Core app

Last Update: 5/26/2017

Team Services | TFS 2017 | Previous versions: XAML Build, Release

Are you new to Team Build, Release Management, or CI/CD? If so, we recommend that you first read CI/CD for newbies and then come back here after that.

ASP.NET Core is a lean and composable framework for building web and cloud applications. Here we'll show you how to define your continuous integration (CI) process.

Get set up

For the instructions in this topic, you need an ASP.NET Core project in Visual Studio 2017 or Visual Studio 2015 Update 3.

TIP

If you don't yet have an app but want to try this out, then see the Q&A below.

Create the build definition

  1. Open your team project in your web browser ▼

    Browse to team project

    (If you don't see your team project listed on the home page, select Browse.)

    • On-premises TFS: http://{your_server}:8080/tfs/DefaultCollection/{your_team_project}
    • Visual Studio Team Services: https://{your_account}.visualstudio.com/DefaultCollection/{your_team_project}

    The TFS URL doesn't work for me. How can I get the correct URL?

  2. Create a build definition (Build & Release tab > Builds) ▼

    Build tab

  3. Where is your code?
    • Team Services: Select the ASP.NET Core (PREVIEW) template
    • TFS: Start with an empty process.
  4. As the repository source, select the team project, repository, and branch.

Add build tasks

Team Services

After you select the ASP.NET Core (PREVIEW) template, instances of the .NET Core task are added to your build definition to restore, build, test, and publish the app.

A publish build artifacts task is also added. This task publishes your web deploy package as an artifact. Your CD release process uses this package to deploy your app.

NOTE

There's a known issue with the .NET Core task publish command created by the template. it doesn't target a specific project. The workaround is to make sure you've got only a single project in your repository.

TFS 2017

Add the following tasks.

icon
Utility: Command Line

Restore NuGet packages.

  • Tool: dotnet
  • Arguments: restore
  • Advanced, Working folder: Folder in which the project.json file (for projects created with VS 2015) or .csproj file (for projects created with VS 2017) exists.
icon
Build: Visual Studio Build

(Optional) Build any additional projects that are checked in.

  • Solution: **\*.sln
  • Platform: $(BuildPlatform)
  • Configuration: $(BuildConfiguration)
  • Visual Studio Version: Select Visual Studio 2015 if your project was created in VS 2015 Update 3. Select Visual Studio 2017 if your project was created in VS 2017.
Command line
Utility: Command Line

Build your ASP.NET Core project and publish the output to a folder.

  • Tool: dotnet
  • Arguments: publish -c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)
  • Advanced, Working folder: Folder in which the project.json file (for projects created with VS 2015) or .csproj file (for projects created with VS 2017) exists.
icon
Test: Visual Studio Test

(Optional) Run your tests. See

icon
Utility: Archive Files

Archive the output into a web deploy package.

  • Root folder to archive: $(Build.ArtifactStagingDirectory)
  • Prefix root folder name to archive paths: Clear this check box
  • Archive type: zip
  • Artifact file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
icon
Utility: Publish Build Artifacts

Publish the build artifacts to be consumed by a release definition.

  • Path to publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
  • Artifact name: drop
  • Artifact type: Server

Define variables

On the Variables tab, add the following variables:

Name Value
BuildConfiguration release
BuildPlatform any cpu

Enable continuous integration (CI)

On the Triggers tab, enable continuous integration (CI). This tells the system to queue a build whenever someone on your team commits or checks in new code.

Select the default agent queue

Click the Options or General tab.

TIP

In general your build will run faster with private agents, especially if you don't clean the repository.

Visual Studio 2017

For the default agent queue, select Hosted VS2017. If you're using TFS or Team Services with private agents, select the queue connected with a pool that has agents with Visual Studio 2017 installed.

Visual Studio 2015

For the default agent queue, select Hosted. If you're using TFS or Team Services with private agents, select the queue connected with a pool that has agents with Visual Studio 2015 installed.

Queue and test the build

Save the build definition and queue a new build by selecting the Queue new build command.

Once the build is done (after a couple of minutes), click on the build number (such as "Build 332"), click the Artifacts tab, and then Explore to see the zip file produced by the build. This is the web deploy package that your release definition will consume to deploy your app.

Deploy your app

After you've run the build, you're ready to create a release definition to deploy your app to:

Q&A

How do I create an ASP.NET Core solution?

  1. If you are using Visual Studio 2015 Update 3, then install .NET Core 1.0.1 - VS 2015 Tooling Preview 2 or newer. If you are using Visual Studio 2017, then you're all set and can skip to the next step.

  2. In Visual Studio, connect to your team project.

  3. On the Team Explorer home page (Keyboard: Ctrl + 0, H), under Solutions, click New.

  4. Select the Visual C# templates node, the Web sub-node.

  5. Select ASP.NET Core Web Application (.NET Core) and click OK.

  6. Select Web Application from the template list.

  7. Make sure Authentication is set to No Authentication.

  8. Visual Studio 2013: Make sure Host in the cloud is not checked, and then click OK.

  9. Commit and push (Git) or check in (TFVC) your code.

Where can I learn more about ASP.NET Core?

Introduction to ASP.NET Core

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.