Unable to Build Azure Web App in Deployment Sync When Targeting .NET 8

Bruce Phillips 0 Reputation points
2024-09-24T13:42:45.13+00:00

In my web app on Azure I've set the Settings - Configuration - .NET Version to 8.0 LTS and in my source could I've targeted .NET 8.

I can build locally in Visual Studio

When I sync my source code from my BitBucket repository to my deployment in Azure app service I get this error;

Build FAILED.

"C:\home\site\repository\ConferenceSubmission\ConferenceSubmission.csproj" (Restore target) (1) ->
"C:\home\site\repository\ConferenceSubmission\ConferenceSubmission.csproj" (_GenerateRestoreGraphProjectEntry target) (1:5) ->
(_CheckForUnsupportedNETCoreVersion target) -> 
  C:\Program Files (x86)\dotnet\sdk\6.0.424\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. [C:\home\site\repository\ConferenceSubmission\ConferenceSubmission.csproj]

    0 Warning(s)
    1 Error(s)

It looks like despite setting the Settings - Configuration- .NET version to 8 Azure is still trying to build my web app using sdk 6.0.424.

How can I tell Azure to use .NET SDK 8.0.303 which is installed on my app servce when I check via the console
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,823 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
921 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 16,196 Reputation points Microsoft Employee
    2024-09-26T02:34:57.9166667+00:00

    @Bruce Phillips To resolve this issue, you can try specifying the .NET SDK version in your project file. You can do this by adding a global.json file to the root of your project with the following contents:

    {
      "sdk": {
        "version": "8.0.303"
      }
    }
    

    This will tell Azure to use the .NET SDK version 8.0.303 when building your project.

    Alternatively, you can try specifying the .NET SDK version in your deployment script. You can do this by adding the following command to your deployment script:

    export DOTNET_ROOT=/usr/share/dotnet
    export PATH=$PATH:$DOTNET_ROOT
    export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
    export DOTNET_CLI_TELEMETRY_OPTOUT=1
    export DOTNET_SDK_VERSION=8.0.303
    dotnet build
    
    

    This will set the DOTNET_SDK_VERSION environment variable to 8.0.303 and use that version of the .NET SDK when building your project.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.