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

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

我正在扩展一个 Windows 应用程序来分析 C# 代码并检测各种气味。该扩展也将在 GitHub 操作中工作。目的是使用此应用程序将提交的代码作为 CI 周期的一部分进行分析。该应用程序是基于.NET framework 4.7.2的控制台应用程序。

为了将应用程序与 GitHub 操作集成,我将一个 yml 文件放在一起(在下面生成)。其他一切正常,但应用程序失败并显示以下消息。

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

我正在使用以下 yml 文件。如您所见,我已将 MSBuild 添加到路径中,将环境变量设置为使用版本 15,将环境变量 VSINSTALLDIR 设置为 Visual Studio 2017 安装,并安装了构建工具。但是,我仍然收到错误。我错过了什么?

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 Studio17\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

希望我正确理解了你的问题。

查看此问题 https://github.com/microsoft/setup-msbuild/issues/18#issuecomment-644485409

托管代理上只有最新版本的 VS。如果更改 and/or 你有 self-hosted 个代理,版本标志确实存在。

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

最近运行程序在指定版本参数时无法执行此引擎。 解决方法:删除任何对操作的 vs-version 参数的使用,并让它默认为最新的。

经过这么多 hit-and-try 次尝试,我终于做到了 运行。这是工作 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 Studio17\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