基于 Github runner (Ubuntu) 的 Dotnet 构建失败,'N/A' 不是有效的版本字符串

Dotnet build on Github runner (Ubuntu) fails with 'N/A' is not a valid version string

我在 Ubuntu (18.04.4 LTS) 上用 Github 运行ner(运行ning 作为 root)构建了一个 dotnet 项目。构建意外失败(2 次成功 运行s,然后每次都失败)。 当直接从命令行 运行 时,相同的构建命令每次都有效:

dotnet publish --configuration Release ./Gif

我用 github 运行ner:

得到的一致错误
dotnet publish --configuration Release ./Gif
shell: /bin/bash -e {0}
env:
DOTNET_ROOT: /root/.dotnet
VERSION: 123
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
/root/.dotnet/sdk/3.1.415/NuGet.targets(128,5): error : 'N/A' is not a valid version string. (Parameter 'value') [/home/actions-runner/_work/gif-onboarding/gif-onboarding/Gif/Gif.sln]
Error: Process completed with exit code 1.

构建yaml文件:

name: .NET-main

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: self-hosted
    steps: 
    - name: Cleanup
      run: 
        rm -rf ./*
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.x
    - name: Build
      env: 
        VERSION: "123"
      run: dotnet publish --configuration Release ./Gif
    - name: Deploy
      run: |
        cp -a ./Gif/GifOnboarding/bin/Release/netcoreapp3.1/* /var/www/dotnet/

我试验过“env:VERSION”参数。在一系列失败之后——当我添加 env:VERSION 参数时——它成功了两次,然后又回到错误状态。我无法使用 adding/removing 将 env:version 复制到 yaml 文件。

引用的 /3.1.415/NuGet.targets(128,5) 如下所示:

 <RestoreTask
      RestoreGraphItems="@(_RestoreGraphEntryFiltered)"
      RestoreDisableParallel="$(RestoreDisableParallel)"
      RestoreNoCache="$(RestoreNoCache)"
      RestoreIgnoreFailedSources="$(RestoreIgnoreFailedSources)"
      RestoreRecursive="$(RestoreRecursive)"
      RestoreForce="$(RestoreForce)"
      HideWarningsAndErrors="$(HideWarningsAndErrors)"
      Interactive="$(NuGetInteractive)"
      RestoreForceEvaluate="$(RestoreForceEvaluate)"
      RestorePackagesConfig="$(RestorePackagesConfig)"/>

我该如何进一步解决这个问题?

最终解决方案是将 ENV 变量“version”设置为 1 (int)。对于我需要的每个步骤:

- name: Build
  env: 
    version: 1
  run: dotnet publish --configuration Release ./Gif

我发现如果我 运行:

dotnet restore --ignore-failed-sources -v diag ./Gif/InternalWeb

-v diag输出的部分是:

...
Environment at start of build:
...
version = N/A
...

然后我确保将此变量设置为数值 (1)。现在构建工作正常。