Im upgrading my backends to dotnet 5.0 but now my aws buildpiplines are failing on the aws codebuild step. The docker image im running is Ubuntu 20.04 aws/codebuild/standard:5.0 which definitely supports dotnet5.0.
Here is the error as seen on codebuild:
Step 6/11 : RUN dotnet publish -c Release -o out
---> Running in f2d4da28b101
5.0.301 [/usr/share/dotnet/sdk]
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'publish' does not exist.
* You intended to execute a .NET SDK command:
A compatible installed .NET SDK for global.json version [5.0.202] from [/app/global.json] was not found.
Install the [5.0.202] .NET SDK or update [/app/global.json] with an installed .NET SDK:
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 145
Finding this really wierd because my dockerfile below clearly pulls the sdk version
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build-env /app/out .
ENV ASPNETCORE_URLS http://*:443
ENTRYPOINT ["dotnet", "user-bff.dll"]
version: 0.2
phases:
install:
runtime-versions:
dotnet: 5.0
pre_build:
commands:
- echo Logging in to Amazon ECR
- aws ecr get-login-password | docker login --username AWS --password-stdin $REPOSITORY_URI
- IMAGE_URI="${REPOSITORY_URI}:latest"
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build --tag "$IMAGE_URI" .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:latest
post_build:
commands:
- echo Build completed on `date`
- echo Push the latest Docker Image...
- docker push "$IMAGE_URI"
- printf '[{"name":"user-bff","imageUri":"%s"}]' "$IMAGE_URI" > images.json
artifacts:
files:
- buildspec.yml
- images.json
Also heres my buildspec file
Looking for any help possible! think it may be related to ubuntu because it works completely fine on my local windows machine. The only thing i changed from when it was working was the runtime image, codebuild image and updating my apps to dotnet 5.0
Same issue here - turns out it's the buildspec install phase outcome that's causing issues. As the dotnet 5.x is installed, global.json file is generated. This file dictates which SDK is required/supported (more here: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json).

The SDK version installed by the buildspec phase is 5.0.202., but as you noted, the docker image you are using already has relevant SDK (currently 5.0.301).
When the Docker build starts, you copy that global.json file (statement COPY . ./) into your project structure effectively adding restriction on what SDK should be used to build the project. This is producing build failure as the SDK required (by the global.json) is not present.
To fix it make sure that global.json file is removed prior to running SDK related statements (build, publish..). You can modify the pre-build phase and remove the specified file and the Docker build should go through smoothly.
pre_build:
commands:
- echo Removing global.json file
- rm ./global.json -f
- ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With