Using CodeBuild with ASP.NET Core

With the recent announcements from AWS, AWS CodeBuild is now capable of building and deploying .NET Core applications. In this short column, I will demonstrate how I was able to build a sample ASP.NET Core application.

In this example I used CodeCommit to host my repo. I also tried it with Github and it worked exactly the same way.

Let’s start by creating a new .NET Core application

dotnet new mvc --name SampleCore

After initialising git on the repo, let’s go ahead and create the repository in CodeCommit

Create repo

The next thing we want to do is configure CodeBuild with our repository

Configure CodeBuild

And then we connect to our repository in CodeCommit. This is where you can select Github and login with your Github account

Connect to repo

Once that is completed, then we can start the build


Our build was not successful but CodeBuild is complaining about the missing build config

Build error

We need to add our `buildspec.yml` so that CodeBuild knows how to interact with the .NET Core CLI and build our project. Our build specification looks like the following:

version: 0.2
- echo Restore started on `date`
- dotnet restore SampleCore.csproj
- echo Build started on `date`
- dotnet publish -c release -o ./build_output SampleCore.csproj
- CodeBuild-SampleCore/build_output/**/*
- scripts/**/*

Once we add the file, then we can start a new build, and this time it’s successful.

Build completed

You can review the complete code on github and try it out yourself. If you are interesting in building the complete workflow and you are looking with a solution to automatically provision resources to release the software, then you should check out CodeStar. CodeStar has templates for .NET Core projects as well.

No Comments Yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.