We are using the AWS provided aws/codebuild/amazonlinux2-x86_64-standard:5.0
CodeBuild image and installing the .NET 8 SDK in our buildspec file with:
/usr/local/bin/dotnet-install.sh --channel 8.0
which runs successfully, which we confirm with dotnet --list-sdks
and get the following output:
[Container] 2024/03/28 00:29:20.812199 Running command dotnet --list-sdks
6.0.419 [/root/.dotnet/sdk]
8.0.201 [/root/.dotnet/sdk]
8.0.203 [/root/.dotnet/sdk]
However, when we attempt to build/package our .NET 8 app with dotnet lambda package --configuration Release --framework net8.0 --output-package deploy-package.zip
It seems to be ignoring the fact that the .NET 8 SDK is installed and opting for .NET 6. which is incompatible and erroring out.
Executing publish command
... invoking 'dotnet publish', working folder '/codebuild/output/src1972822102/src/MyApp.API/bin/Release/net8.0/publish'
... dotnet publish "/codebuild/output/src1972822102/src/MyApp.API" --output "/codebuild/output/src1972822102/src/MyApp.API/bin/Release/net8.0/publish" --configuration "Release" --framework "net8.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-x64 --self-contained False
... publish: MSBuild version 17.3.2+561848881 for .NET
... publish: Determining projects to restore...
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/MyApp.Core/MyApp.Core.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/WebAst.WebApi.Core/WebAst.WebApi.Core.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/MyApp.Utilities/MyApp.Utilities.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/WebAst.AWS.Utilities/WebAst.AWS.Utilities.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/MPR.Cognito.Extensions.Reporting/MPR.Cognito.Extensions.Reporting.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/MyApp.API.Reporting/MyApp.API.Reporting.csproj]
... publish: /root/.dotnet/sdk/6.0.419/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [/codebuild/output/src1972822102/src/MyApp.API/MyApp.API.csproj]
ERROR: The dotnet publish command return unsuccessful error code
[Container] 2024/03/28 00:29:32.414499 Command did not exit successfully dotnet dotnet-lambda package --configuration Release --framework net8.0 --output-package deploy-package.zip exit status 255
[Container] 2024/03/28 00:29:32.420173 Phase complete: BUILD State: FAILED_WITH_ABORT
[Container] 2024/03/28 00:29:32.420194 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: dotnet dotnet-lambda package --configuration Release --framework net8.0 --output-package deploy-package.zip. Reason: exit status 255
In roughly the same situation locally (multiple SDK versions installed concurrently [6.X.X, 7.X.X and 8.X.X] - running dotnet build
as well as dotnet lambda package [...]
on this some solution locally, results in success.
Ended on leaning on CodeBuild feature to provide the runtime-versions
you want in the install
phase.
Completely removed the step /usr/local/bin/dotnet-install.sh --channel 8.0
from the buildpsec in favor of the below and it worked just fine.
version: 0.2
phases:
install:
runtime-versions:
dotnet: 8.0
Both 6 and 8 will be concurrently available/installed.
[Container] 2024/03/29 13:48:09.859931 Running command dotnet --list-sdks
6.0.419 [/root/.dotnet/sdk]
8.0.201 [/root/.dotnet/sdk]
But now when running dotnet lambda package --configuration Release --framework net8.0 --output-package deploy-package.zip
the correct SDK is used and the publish/package is sucessful.