Search code examples
.netmsbuildgithub-actionsbuilding-github-actionsgithub-actions-runners

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


I build a dotnet project on Ubuntu (18.04.4 LTS) with a Github runner (running as root). The build unpredictably fails (2 successful runs and then fails every time). The same build command works every-time when run from command-line directly:

dotnet publish --configuration Release ./Gif

The consistent error I get with the 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.

The build yaml file:

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/

I have experimented with the "env:VERSION" parameter. After series of failures - when I added the env:VERSION parameter - it succeeded twice and then it got back to errors. I was not able to reproduce it again with adding/removing the env:version to yaml file.

The referenced /3.1.415/NuGet.targets(128,5) looks like this:

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

How can I troubleshoot this further?


Solution

  • Finally the solution was to set ENV variable "version" to 1 (int). For each step I needed:

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

    I discovered that if I run:

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

    The part of -v diag output was:

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

    I then made sure that this variable was set to numeric value (1). And now the build works as expected.