Running .Net Core 6 on CodeBuild throws SDK not supported error

0

I'm trying to build an infrastructure using CodePipeline and CodeBuild. I've a .NET project with targetFramework set as .Net Core 6. When the CodeBuild process triggers the build, it throws an error

/root/.dotnet/sdk/5.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(141,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.

If I switch the targetFramework to .Net Core 3.1 or 5, it works fine. Has anyone faced this issue before? If yes, how did they overcome it?

1 Antwort
0

After doing some digging and talking to couple of folks, I realized that CodeBuild doesn't support .Net Core 6 yet. But there is a work around by explicitly installing the latest SDKs on the container as part of your infrastructure setup.

I added the following command to my synth workflow which installed the latest SDKs on the docker.

"/usr/local/bin/dotnet-install.sh --channel LTS"

There are different ways to use it depending on your use case. I've added in my C# code as a Install Command when building the pipeline

        private static readonly string[] InstallCommands =
        {
            "/usr/local/bin/dotnet-install.sh --channel LTS" 
        };

 var synth = new ShellStep("Synth",
                new ShellStepProps
                {
                    InstallCommands = InstallCommands,
                });

            var pipeline = new CodePipeline(this, "Pipeline", new CodePipelineProps { Synth = synth });

I believe it can also be added to buildspec.yml file. There's an example in following link.

Reference: https://github.com/aws/aws-codebuild-docker-images/issues/497

When to expect official .Net Core 6 support on Code Build

I believe the support for .Net Core 6 with CodeBuild will be available in the near future. Found some additional resource for Core 6 support on different AWS Services.

AWS
Chief
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen