Executing a Windows application within GitHub Actions (Error: The tools version "15.0" is unrecognized)

Viewed 1179

I am extending a Windows application that analyzes C# code and detects various smells. The extension will also work within GitHub Action. The intent is to analyze the committed code as part of CI cycle using this application. The application is a console application based on .NET framework 4.7.2.

To integrate the application with the GitHub Actions, I put together a yml file (produced below). Everything else works fine but the application fails with the following message.

The tools version "15.0" is unrecognized. Available tools versions are "2.0", "3.5", "4.0". 

I am using the following yml file. As you may observe, I have added MSBuild to the path, set the environment variable to use version 15, set environment variable VSINSTALLDIR to the Visual Studio 2017 installation, and installed build tools. However, I still get the error. What am I missing?

Name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    # Add  MsBuild to the PATH: https://github.com/microsoft/setup-msbuild
    - name: Setup MSBuild.exe
      uses: microsoft/setup-msbuild@v1.0.0
      with:
          vs-version: '15.0'

    - name: env var
      run: echo ::set-env name=VSINSTALLDIR::"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"

    - name: checking sdk
      run: echo ::set-env name=VisualStudioVersion::"15.0"

    - name: install build tools
      run: |
        curl.exe -o buildtools.exe https://download.visualstudio.microsoft.com/download/pr/3e542575-929e-4297-b6c6-bef34d0ee648/639c868e1219c651793aff537a1d3b77/vs_buildtools.exe
        .\buildtools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.UniversalBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools
    
    # Runs a set of commands using the runners shell
    - name: download DesigniteConsole.exe
      run: |
        curl.exe -o DesigniteConsole.zip "<download link>"
        powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('DesigniteConsole.zip','.');}"
    
    - name: Run Designite application (it utilizes GitHub secrets and environment variables)
      run: |
        .\DesigniteConsole\DesigniteConsole.exe -ci -repo ${{github.repository}} -pat ${{ secrets.PAT }} -k ${{ secrets.D_KEY }}
        cat Designite_output/DesigniteAnalysis.xml
2 Answers

After so many hit-and-try attempts, I was able to make it run. Here is the working yaml.

Name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2

    - name: Run a one-line script
      run: Invoke-webrequest -uri  https://aka.ms/vs/15/release/vs_buildtools.exe -OutFile vs_buildtools.exe
      shell: powershell

    - name: install build tools
      run: .\vs_buildtools.exe --wait --norestart --passive --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools
      shell: cmd
    
    # Runs a set of commands using the runners shell
    - name: download DesigniteConsole.exe
      run: |
        curl.exe -o DesigniteConsole.zip "<download link>"
        powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('DesigniteConsole.zip','.');}"
    
    - name: Run Designite application (it utilizes GitHub secrets and environment variables)
      run: |
        .\DesigniteConsole\DesigniteConsole.exe -ci -repo ${{github.repository}} -pat ${{ secrets.PAT }} -k ${{ secrets.D_KEY }}
        cat Designite_output/DesigniteAnalysis.xml

Hope I understood your question correctly.

Check out this issue https://github.com/microsoft/setup-msbuild/issues/18#issuecomment-644485409

The hosted agents only have latest version of VS on them. The version flag is really there in the event that changes and/or you have self-hosted agents.

or

https://github.com/microsoft/setup-msbuild/issues/5#issue-588501457

Recently the runner has been failing to execute this engine when specifying a version argument. Workaround: remove any use of vs-version argument for the action and let it default to latest.

Related