You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 8 Web API部署Google App Engine报错:无有效运行时

问题描述

尝试将.NET Core 8 Web API部署至Google App Engine灵活环境,执行gcloud app deploy app.yaml命令后上传成功,但构建阶段报错:

Step #1: No valid .NET Core runtime version found for the app or it is not a supported app.

已配置内容

项目文件(.csproj)

<PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
    <None Update="app.yaml">
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
</ItemGroup>

<ItemGroup>
    <PackageReference Include="Google.Cloud.AIPlatform.V1" Version="2.26.0" />
    <PackageReference Include="Google.Cloud.Diagnostics.AspNetCore" Version="4.4.0" />
    <PackageReference Include="Google.Cloud.Vision.V1" Version="3.6.0" />
    <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.6.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

app.yaml文件

runtime: aspnetcore
env: flex

runtime_config:
  operating_system: "ubuntu22"

完整报错日志片段

Beginning deployment of service [default]...
##
#= Uploading 1 file to Google Cloud Storage =#
#
# File upload done. WARNING: .NET 3 and earlier versions will reach end of
support on 2024-07-10 for App Engine flexible environment. After
2024-07-10, you cannot deploy new or re-deploy existing applications
that use runtimes after their end of support date. We recommend that
you migrate to the latest supported version of .NET.

Updating service [default] (this may take several minutes)...done.
-------------------------------------------------------- REMOTE BUILD OUTPUT --------------------------------------------------------
starting build "050f4aa1-a057-4a88-91be-9c0006c111c3"

FETCHSOURCE BUILD Starting Step #0 - "fetcher" Step #0 - "fetcher":
Already have image (with digest): gcr.io/cloud-builders/gcs-fetcher
Step #0 - "fetcher": Fetching manifest
gs://staging.nodex-labels.appspot.com/ae/0ae19b24-c5d6-4d37-b683-a12381489790/manifest.json.
Step #0 - "fetcher": Processing 57 files. Step #0 - "fetcher":
****************************************************** Step #0 - "fetcher": Status: SUCCESS Step #0 - "fetcher":
Started: 2024-04-25T08:52:51Z Step #0 - "fetcher":
Completed: 2024-04-25T08:52:57Z Step #0 - "fetcher":
Requested workers: 200 Step #0 - "fetcher": Actual workers:

57 Step #0 - "fetcher": Total files: 57 Step #0 - "fetcher":
Total retries: 4 Step #0 - "fetcher": GCS timeouts:

4 Step #0 - "fetcher": MiB downloaded: 271.54 MiB Step #0 -
"fetcher": MiB/s throughput: 48.67 MiB/s Step #0 - "fetcher":
Time for manifest: 949.21 ms Step #0 - "fetcher": Total time:

6.56 s Step #0 - "fetcher": ****************************************************** Finished Step #0 - "fetcher" Starting Step #1 Step #1: Pulling image: gcr.io/gcp-runtimes/aspnetcorebuild@sha256:f5552a5efdaf278a2124ea10fd1c9636b09fc9f98f9e620cbd71279797576b3f
Step #1:
gcr.io/gcp-runtimes/aspnetcorebuild@sha256:f5552a5efdafg78a3124ea10fd1c9636b09fc9f98f9e620cbd71279797576b3f:
Pulling from gcp-runtimes/aspnetcorebuild Step #1: bd0de8be231c:
Pulling fs layer Step #1: 091745073ef1: Pulling fs layer Step #1:
355bf594d611: Pulling fs layer Step #1: 013d0752935b: Pulling fs layer
Step #1: 4c7d0d02eb09: Pulling fs layer Step #1: 013d0752935b: Waiting
Step #1: 4c7d0d02eb09: Waiting Step #1: 355bf594d611: Download
complete Step #1: 013d0752935b: Download complete Step #1:
4c7d0d02eb09: Verifying Checksum Step #1: 4c7d0d02eb09: Download
complete Step #1: 091745073ef1: Verifying Checksum Step #1:
091745073ef1: Download complete Step #1: bd0de8be231c: Verifying
Checksum Step #1: bd0de8be231c: Download complete Step #1:
bd0de8be231c: Pull complete Step #1: 091745073ef1: Pull complete Step
#1: 355bf594d611: Pull complete Step #1: 013d0752935b: Pull complete Step #1: 4c7d0d02eb09: Pull complete Step #1: Digest:
sha256:f5552a5efdaf278a3124ea10fd1c9636b03fc9f98f9e620cbd71279797576b3f
Step #1: Status: Downloaded newer image for
gcr.io/gcp-runtimes/aspnetcorebuild@sha256:f5352a5efdaf278a3124ea10fd1c9636b09fc9f98f9e620cbd71279797576b3f
Step #1:
gcr.io/gcp-runtimes/aspnetcorebuild@sha256:f5552a5efdaf278a3124ea10fd1c9336b09fc9f98f9e620cbd71279797576b3f
Step #1: No valid .NET Core runtime version found for the app or it is
not a supported app. Finished Step #1 ERROR ERROR: build step 1
"gcr.io/gcp-runtimes/aspnetcorebuild@sha256:f5552a5efdaf278a3124ea10fd1c9636b09fc9f98f9e620cbd71279797576b3f"
failed: step exited with non-zero status: 1
------------------------------------------------------------------------------------------------------------------------------------- WARNING: .NET 3 and earlier versions will reach end of support on
2024-07-10 for App Engine flexible environment. After 2024-07-10, you
cannot deploy new or re-deploy existing applications that use runtimes
after their end of support date. We recommend that you migrate to the
latest supported version of .NET.

Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build
050f4aa1-a057-4b88-91be-9c0006c9a9c3 status: FAILURE

解决方案

这个错误是因为App Engine灵活环境的默认构建镜像未正确识别.NET 8,补充以下配置即可解决:

  • 在app.yaml中明确指定.NET版本:
    在runtime_config节点下添加dotnet_version字段,指定使用.NET 8:

    runtime: aspnetcore
    env: flex
    
    runtime_config:
      operating_system: "ubuntu22"
      dotnet_version: "8.0"
    
  • 添加RuntimeIdentifier到项目文件(可选但推荐):
    在项目文件的<PropertyGroup>中添加目标运行时标识,确保构建产物匹配Ubuntu环境:

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
    </PropertyGroup>
    
  • 更新gcloud CLI到最新版本:
    旧版本gcloud对.NET 8支持不完善,执行命令更新:

    gcloud components update
    

完成上述配置后,重新执行gcloud app deploy app.yaml即可正常部署。


内容的提问来源于stack exchange,提问作者De Wet van As

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 05:27:04