Building .NET 7 Applications using Amazon CodeCatalyst

·

3 min read

This past re:Invent AWS Launched Amazon CodeCatalyst the new All-In-One DevOps service. CodeCatalyst provides you with a single pane of glass to source control management, handling pull requests, issue management and software builds.

CodeCatalyst uses the new AWS Builder ID for authentication, which makes it easier for teams of people to collaborate without having to create IAM users. CodeCatalyst also allows you to swap out components like Source Control and Issue management with third parties like Atlasian Jira and GitHub if you already have existing investments in those technologies.

At launch, CodeCatalyst supports .NET 6 as the supported build environment for your .NET applications, due to .NET 6 being the current LTS version of .NET. The good news is that CodeCatalyst's build system is flexible enough that you can easily install and .NET 7 for your build steps.

Here's how:

When you build your workflow for your project in CodeCatalyst, you will have a YAML file that looks similar to this:

Name: Workflow_9835
SchemaVersion: "1.0"

# Optional - Set automatic triggers.
Triggers:
  - Type: Push
    Branches:
      - main

# Required - Define action configurations.
Actions:
  Build_88:
    # Identifies the action. Do not modify this value.
    Identifier: aws/build@v1

    # Specifies the source and/or artifacts to pass to the action as input.
    Inputs:
      # Optional
      Sources:
        - WorkflowSource # This specifies that the action requires this Workflow as a source

    Outputs:
      # Optional; Automatically discover reports for popular test frameworks
      AutoDiscoverReports:
        Enabled: true
        # Use as prefix for the report files
        ReportNamePrefix: rpt

    # Defines the action's properties.
    Configuration:
      # Required - Steps are sequential instructions that run shell commands
      Steps:
        - Run: dotnet restore
        - Run: dotnet build

My workflow above has a single Build stage that includes commands to do a dotnet restore, and a dotnet build command. As mentioned, these will automatically use the .NET 6 runtime that is included by default in the CodeCatalyst build image.

If you add the following line to your build step, before your .NET Build command:

- Run: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel STS

You will automatically download an install the latest .NET runtime from the Standard Term Support (STS) channel. Once the installation completes, your build will use the latest version of .NET, in this case .NET 7, in this case 7.03.

If you want more control over the version of .NET that gets installed, you can change the channel to be a specific version.

- Run: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 7.0

Once you have updated your workflow, click the commit button at the top right of the screen and CodeCatalyst will start building your project with .NET 7.

The complete, updated workflow definition looks like this:

Name: Workflow_9835
SchemaVersion: "1.0"

# Optional - Set automatic triggers.
Triggers:
  - Type: Push
    Branches:
      - main

# Required - Define action configurations.
Actions:
  Build_88:
    # Identifies the action. Do not modify this value.
    Identifier: aws/build@v1

    # Specifies the source and/or artifacts to pass to the action as input.
    Inputs:
      # Optional
      Sources:
        - WorkflowSource # This specifies that the action requires this Workflow as a source

    Outputs:
      # Optional; Automatically discover reports for popular test frameworks
      AutoDiscoverReports:
        Enabled: true
        # Use as prefix for the report files
        ReportNamePrefix: rpt

    # Defines the action's properties.
    Configuration:
      # Required - Steps are sequential instructions that run shell commands
      Steps:
        - Run: curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 7.0
        - Run: dotnet restore
        - Run: dotnet build

At the point that I am writing this article, the .NET Install scripts don't seem to support installing the .NET 8 preview, and Microsoft doesn't appear to have a .NET 8 Preview 1 installer for Linux yet. As soon as it does, I'll post a followup post with how you can get .NET 8 Preview 1 into CodeCatalyst as well.

Did you find this article valuable?

Support Tom Moore by becoming a sponsor. Any amount is appreciated!