1

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

dotnet publish --configuration Release ./Gif

我使用 github runner 得到的一致错误:

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 参数时 - 它成功了两次,然后又回到错误。通过将 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)"/>

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

4

1 回答 1

0

最后的解决方案是将 ENV 变量“版本”设置为 1(整数)。对于我需要的每个步骤:

- 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)。现在构建按预期工作。

于 2021-11-09T20:50:09.973 回答