Skip to content

Create msbuild2.yml

Create msbuild2.yml #4

Workflow file for this run

name: CMake Build with vcpkg and MSVC
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
BUILD_TYPE: Release # 可以改成 Debug
permissions:
contents: read
jobs:
build:
runs-on: windows-latest # 使用 Windows 环境
steps:
- uses: actions/checkout@v4 # 检出代码
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v2 # 将 MSBuild 添加到 PATH
- name: Set up vcpkg
run: |
# 克隆 vcpkg 仓库
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
# 安装 vcpkg 并初始化
./bootstrap-vcpkg.bat
# 安装所需的第三方库(webview2, simpleini, fmt)
./vcpkg install webview2 simpleini fmt
- name: Configure CMake with vcpkg toolchain
run: |
cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
- name: Build the project with MSVC
run: |
cmake --build ${{ github.workspace }}/build --config ${env.BUILD_TYPE}
- name: Run tests (optional)
run: |
ctest --build-directory ${{ github.workspace }}/build --config ${env.BUILD_TYPE}