解决 GitHub Actions 中的 MSVC141 问题
我们正在开发一个 Visual Studio 2019 项目,该项目最近开始抛出与丢失文件(特别是“atlbase.h”)相关的异常。此问题似乎是由于缺少 MSVC141 工具集造成的,而直到几个月前才需要该工具集。
在本文中,我们将指导您如何更新 GitHub Actions 中的 .yml 脚本以包含 MSVC141 工具集。这可确保项目构建顺利并避免“无法打开包含文件”错误,帮助您保持开发工作流程的生产力。
命令 | 描述 |
---|---|
uses: microsoft/setup-msbuild@v1.1 | 为 GitHub Actions 设置 MSBuild,以便构建 .NET 项目。 |
vs-version: 2019 | 指定要使用的 Visual Studio 版本,确保与 MSVC141 工具集的兼容性。 |
msbuild-version: 16.x | 定义 MSBuild 版本,与编译所需的 MSVC141 工具集保持一致。 |
extenda/actions/setup-nuget-sources@v0 | 在 GitHub Actions 中配置 NuGet 源,这对于恢复项目依赖项至关重要。 |
nuget restore POS.sln | 恢复指定解决方案的 NuGet 包,在构建之前解决所有依赖项。 |
Copy-Item | 在 PowerShell 中将文件从一个位置复制到另一个位置,此处用于处理数据库模板。 |
Start-Process | 在 PowerShell 中启动新进程,对于运行安装程序或其他可执行文件很有用。 |
vswhere.exe | 用于定位 Visual Studio 安装的实用程序,用于检查 MSVC141 是否存在。 |
在 GitHub Actions 中集成 MSVC141 工具集
上面提供的脚本可确保 MSVC141 工具集包含在您的 GitHub Actions 工作流程中。第一个脚本更新 YAML 配置文件以包括设置所需工具和环境所需的步骤。这包括使用以下命令设置 MSBuild ,指定 Visual Studio 版本 ,并确保 用来。这些步骤可确保构建环境正确配置为使用 MSVC141。
此外,PowerShell 脚本使用以下命令检查 MSVC141 工具集是否存在: 。如果未找到,该脚本将通过运行来启动安装过程 以及安装缺少的组件所需的参数。这种自动化方法可确保所需的工具集可用,从而防止 与缺少“atlbase.h”等包含文件有关。通过执行这些步骤,您可以在 GitHub Actions 中维护 Visual Studio 2019 项目的稳定且一致的构建过程。
更新 .yml 脚本以包含 MSVC141 工具集
GitHub 操作 YAML 配置
name: Pull request - Windows
on:
pull_request:
paths-ignore:
- 'Engine/Engine.Android/'
- 'Mobile/'
jobs:
build:
runs-on: windows-2022
defaults:
run:
shell: pwsh
env:
DEFAULT_VERSION: v17.4.500
SolutionDir: ${{ github.workspace }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.RS_GITHUB_TOKEN }}
submodules: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.1
- name: Install Visual Studio
uses: microsoft/setup-msbuild@v1.1
with:
vs-version: 2019
msbuild-version: 16.x
- name: Setup NuGet sources
uses: extenda/actions/setup-nuget-sources@v0
with:
config-file: NuGet.Config
sources: |
[{
"name": "Nexus",
"source": "https://repo.extendaretail.com/repository/nuget-hosted/",
"username": "${{ secrets.NEXUS_USERNAME }}",
"password": "${{ secrets.NEXUS_PASSWORD }}",
"apikey": "${{ secrets.NUGET_API_KEY }}"
}]
- name: Restore NuGet packages
run: nuget restore POS.sln
- name: Determine version
id: ver
run: .\Build\determine-version.ps1
- name: Update assemblies
run: .\Build\update-assemblies.ps1 ${{ steps.ver.outputs.version }} ${{ steps.ver.outputs.full-version }}
- name: Generate database template
run: |
.\Common\Database\AppVeyor\gen-databases.ps1 Common\Database abcDb
Copy-Item abcDb\Template.db -Destination Common\Database
- name: Build solution
run: msbuild POS.sln @Build\WindowsBuildParams.rsp
- name: Build installation packages
run: |
.\Build\exit-on-failure.ps1
msbuild Installation\Installation.sln @Build\WindowsBuildParams.rsp -p:BuildNumber=${{ steps.ver.outputs.full-version }}
ExitOnFailure
Get-ChildItem Installation\Bin\Release
Rename-Item -Path Installation\Bin\Release\abc.msi -NewName abc-v${{ steps.ver.outputs.full-version }}.msi
Rename-Item -Path Installation\Bin\Release\abc.exe -NewName abc-v${{ steps.ver.outputs.full-version }}.exe
Rename-Item -Path Installation\Bin\Release\VRRSSurfaceComponentsEditor.msi -NewName SurfaceComponentsEditor-v${{ steps.ver.outputs.full-version }}.msi
- name: Generate customization package
run: .\Common\Database\AppVeyor\gen-customization-zip.ps1 Common\Database ${{ steps.ver.outputs.full-version }}
- name: Save abc Installer
uses: actions/upload-artifact@v3
with:
name: abcInstaller-v${{ steps.ver.outputs.full-version }}
path: Installation\Bin\Release\abc-*.msi
- name: Save abc Setup
uses: actions/upload-artifact@v3
with:
name: abcSetup-v${{ steps.ver.outputs.full-version }}
path: Installation\Bin\Release\abc-*.exe
- name: Save Database
uses: actions/upload-artifact@v3
with:
name: Database-v${{ steps.ver.outputs.full-version }}
path: Common\Database\CustomizationTemplate\*
确保 GitHub Actions 中的 MSVC 工具集正确
用于检查和安装 MSVC141 的 PowerShell 脚本
$vswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
if (-Not (Test-Path $vswherePath)) {
Write-Error "vswhere.exe not found at $vswherePath"
exit 1
}
$vsInstallPath = & $vswherePath -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (-Not $vsInstallPath) {
Write-Output "MSVC141 not found. Installing..."
Start-Process -FilePath "cmd.exe" -ArgumentList "/c start /wait vs_installer.exe --quiet --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --includeRecommended --includeOptional" -Wait
if ($?) {
Write-Output "MSVC141 installation completed."
}
else {
Write-Error "Failed to install MSVC141."
exit 1
}
} else {
Write-Output "MSVC141 already installed at $vsInstallPath"
}
exit 0
确保与 GitHub Actions 中的 MSVC 工具集兼容
在 GitHub Actions 等持续集成 (CI) 环境中保持与各种工具集的兼容性对于确保一致的构建和最大限度地减少错误至关重要。一个关键方面是使用必要的工具和依赖项使您的配置文件保持最新。就 MSVC141 而言,重要的是要了解该工具集对于某些项目至关重要,尤其是那些依赖较旧 C++ 库和组件的项目。
在 GitHub Actions 设置中包含 MSVC141 工具集不仅涉及指定正确的 Visual Studio 版本,还涉及确保解决所有依赖项。这包括正确配置 NuGet 源并使用诸如 验证安装。在您的系统中自动执行这些步骤 PowerShell 脚本有助于防止构建失败并保持 CI/CD 管道顺利运行,最终节省开发时间和资源。
- 如何在 GitHub Actions 中指定 Visual Studio 版本?
- 使用 在你的 配置以设置所需的 Visual Studio 版本。
- 什么是 为什么使用它?
- 是一个用于查找 Visual Studio 安装的实用程序,确保所需的工具集可用。
- 如何自动安装缺少的组件?
- 使用 在 PowerShell 中使用无人值守安装所需的参数运行安装程序。
- 为什么配置 NuGet 源很重要?
- 配置 NuGet 源可确保解决所有项目依赖项,这对于成功构建至关重要。
- 如何检查 MSVC141 工具集是否存在?
- 使用 在脚本中验证 MSVC141 工具集的安装路径。
- 什么是 指定?
- 它指定要使用的 MSBuild 版本,确保与 MSVC141 工具集的兼容性。
- 如何在 GitHub Actions 中恢复 NuGet 包?
- 使用命令 接下来是您的解决方案文件,例如 。
- 目的是什么 行动?
- 它将环境配置为使用 MSBuild,这是在 GitHub Actions 中构建 .NET 项目所必需的。
- 如何自动重命名构建工件?
- 使用 PowerShell 命令,例如 根据构建版本重命名文件。
- 为什么包括 在 Java 设置中?
- 这指定要使用的 JDK 发行版,确保为您的项目安装正确的 Java 版本。
确保 MSVC141 工具集包含在 GitHub Actions 工作流程中对于维护 Visual Studio 2019 项目的稳定性和功能至关重要。通过更新 .yml 脚本并自动化安装过程,您可以防止与丢失文件相关的常见构建错误。这种主动方法不仅可以节省时间,还可以提高 CI/CD 管道的效率,从而实现更顺畅、更可靠的项目构建。