How to Update MSVC141.yml Scripts on GitHub

How to Update MSVC141.yml Scripts on GitHub
How to Update MSVC141.yml Scripts on GitHub

Resolving MSVC141 Issues in GitHub Actions

Our project using Visual Studio 2019 has been experiencing problems lately, notably linked to missing files called "atlbase.h." The lack of the MSVC141 toolset, which was not necessary until a few months ago, appears to be the cause of this problem.

We'll walk you through updating your GitHub Actions.yml scripts to use the MSVC141 toolset in this article. This keeps your development workflow productive by preventing the 'cannot open include file' problem and ensuring seamless project builds.

Command Description
uses: microsoft/setup-msbuild@v1.1 Configures MSBuild for GitHub Actions, enabling the development of.NET applications.
vs-version: 2019 Specifies the Visual Studio version should be used in order to guarantee compatibility with the MSVC141 toolkit.
msbuild-version: 16.x Specifies the MSBuild version in accordance with the MSVC141 toolkit requirements for compilation.
extenda/actions/setup-nuget-sources@v0 Sets up NuGet sources in GitHub Actions, which is necessary to get project dependencies back.
nuget restore POS.sln Before building, all dependencies are resolved and NuGet packages are restored for the given solution.
Copy-Item PowerShell file cloning is utilized in this instance to manage database templates.
Start-Process In PowerShell, this creates a new process that may be used to launch executables such as installers.
vswhere.exe A tool to identify Visual Studio installations and determine whether MSVC141 is present.

Using the MSVC141 Toolset with GitHub Action Integration

The scripts mentioned above make sure that your GitHub Actions workflow incorporates the MSVC141 toolset. The first script adds instructions for configuring the relevant environments and tools to the YAML configuration file. This entails using microsoft/setup-msbuild@v1.1 to set up MSBuild, vs-version: 2019 to specify the Visual Studio version, and making sure msbuild-version: 16.x is utilized. By doing these steps, you may ensure that the build environment is set up properly to utilize MSVC141.

Furthermore, the PowerShell script uses vswhere.exe to determine whether the MSVC141 toolset is present. The script starts the installation process by running Start-Process with the required inputs to install the missing components if it cannot be found. By using an automated method, the necessary toolset is guaranteed to be present, avoiding the fatal error C1083 associated with include files such as 'atlbase.h'. You may keep your Visual Studio 2019 projects in GitHub Actions with a reliable and consistent build process by following these instructions.

Add the MSVC141 Toolset to the updated.yml script.

GitHub Actions YAML Configuration

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

Verify the Accurate MSVC Toolset in GitHub Operations

A PowerShell Script to Install and Verify MSVC141

$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

Making GitHub Actions Compliant with MSVC Toolsets

Ensuring consistent builds and avoiding failures in a continuous integration (CI) system such as GitHub Actions requires maintaining compatibility with several toolsets. Maintaining your configuration files with the most recent versions of the required dependencies and tools is essential. Regarding MSVC141, it's critical to realize that this toolkit is necessary for some projects, particularly those that depend on antiquated C++ libraries and parts.

It's important to make sure all dependencies are satisfied in addition to selecting the appropriate Visual Studio version when adding the MSVC141 toolset to your GitHub Actions configuration. This includes utilizing tools like vswhere.exe to validate installs and properly configure NuGet sources. By automating these processes in your PowerShell and .yml scripts, you can reduce development time and resource consumption by preventing build failures and maintaining the efficiency of your CI/CD pipeline.

Frequently Asked Questions and Answers Regarding MSVC Toolset Integration

  1. How can I tell the version of Visual Studio to use in GitHub Actions?
  2. To specify the preferred Visual Studio version, use vs-version: 2019 in your .yml configuration.
  3. vswhere.exe: what is it and why is it used?
  4. A tool to find Visual Studio installations and make sure the necessary toolkits are available is called vswhere.exe.
  5. How can I program the installation of components that are missing?
  6. To execute the installer with the required inputs for unattended installations, use PowerShell's Start-Process command.
  7. Why is setting up NuGet sources important?
  8. A successful build depends on all project dependencies being resolved, which is ensured by configuring NuGet sources.
  9. How can I find out if the MSVC141 toolkit is installed?
  10. To confirm the MSVC141 toolset installation path, use vswhere.exe in a script.
  11. What does msbuild-version: 16.x specify?
  12. It indicates the version of MSBuild should be used in order to ensure that the MSVC141 toolset is compatible.
  13. In GitHub Actions, how can I restore NuGet packages?
  14. Use your solution file after the command nuget restore, such as nuget restore POS.sln.
  15. What is the action's Setup MSBuild goal?
  16. It sets up the environment to use MSBuild, which is required in order for GitHub Actions to build.NET applications.
  17. How can I automatically rename my build artifacts?
  18. To rename files according to the build version, use PowerShell commands such as Rename-Item.
  19. How come distribution: 'temurin' is included in the Java setup?
  20. In order to ensure that the right Java version is installed for your project, this specifies the JDK distribution to use.

Concluding Remarks on Integrating MSVC141

Maintaining the functionality and stability of your Visual Studio 2019 projects requires that the MSVC141 toolset be a part of your GitHub Actions routine. You may avoid typical build issues related to missing files by automating the installation process and updating your.yml scripts. This proactive strategy improves the effectiveness of your CI/CD pipeline and saves time, enabling more streamlined and dependable project builds.