【问题标题】:AppVeyor CI: use build script for linux and MSBuild for WindowsAppVeyor CI:使用适用于 linux 的构建脚本和适用于 Windows 的 MSBuild
【发布时间】:2023-03-04 21:55:01
【问题描述】:

场景

我在 AppVeyor 上有一个 CMake 项目,我正在尝试将 Linux 构建添加到其中。我的 Windows 构建使用 before_build 脚本中的 CMake 生成器来生成使用 build: project 构建的 Visual Studio 解决方案。

我想改用build_script: 执行我的Linux 构建。但是,当我将构建脚本添加到矩阵时,我得到了错误:

构建阶段设置为“MSBuild”模式(默认),但在根目录中未找到 Visual Studio 项目或解决方案文件。如果您不构建 Visual Studio 项目,请将构建模式切换为“脚本”并提供您的自定义构建命令。

尝试的解决方案

我尝试将build: offbuild: Script 添加到矩阵中,但是这些选项都没有帮助。我唯一的选择是为 Windows 定义脚本并在两个平台上使用 build_script

示例

我的appveyor.yml 文件如下所示

version: 'build-{build}-{branch}'

image:
  - Visual Studio 2017
  - Ubuntu

platform:
  - x64

configuration:
  - Release
  - Debug

environment:
  APPVEYOR_YML_DISABLE_PS_LINUX: true

install:
  - ps: .\install-dependency.ps1
  - sh: ./install-dependency.sh

for:
-
  matrix:
    only:
      - image: Ubuntu
  before_build:
    - mkdir -p build; cd build; cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% ..
  build_script:
    - make

 -
   matrix:
     only:
       - image: Visual Studio 2017
   before_build:
     - cmake -G "Visual Studio 15 2017" -A x64 .
   build:
     project: $(APPVEYOR_PROJECT_NAME).sln

test_script:
  - CTest -C %CONFIGURATION%

尝试的解决方案详情

作为参考,这是我尝试指定构建选项的方式

matrix:
  only:
    - image: Ubuntu
build: Script
before_build:
  - mkdir -p build; cd build; cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% ..

进一步研究

我尝试执行独立的 Linux 构建,一切正常,我不需要修改任何 script 参数。即使设置了矩阵,AppVeyor 也不支持混合构建类型。

version: 'build-{build}-{branch}'

image: Ubuntu

platform:
  - x64

configuration:
  - Release
  - Debug

install:
  - sh: ./install-dependency.sh

before_build:
  - mkdir -p build; cd build; cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% ..

build_script:
  - make

test_script:
  - ctest -C %CONFIGURATION%

【问题讨论】:

    标签: appveyor


    【解决方案1】:

    虽然我还没有找到问题的解决方案,但有一种解决方法可以在两个平台上构建。对于 Windows,我可以使用 default MSBuild 脚本 msbuild <project> /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

    version: 'build-{build}-{branch}'
    
    image:
      - Visual Studio 2017
      - Ubuntu
    
    platform:
      - x64
    
    configuration:
      - Release
      - Debug
    
    environment:
      APPVEYOR_YML_DISABLE_PS_LINUX: true
    
    install:
      - ps: .\install-dependency.ps1
      - sh: ./install-dependency.sh
    
    for:
    -
      matrix:
        only:
          - image: Ubuntu
      before_build:
        - mkdir -p build; cd build; cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% ..
      build_script:
        - make
    
     -
       matrix:
         only:
           - image: Visual Studio 2017
       before_build:
         - cmake -G "Visual Studio 15 2017" -A x64 .
      build_script:
        - msbuild %APPVEYOR_PROJECT_NAME%.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
    
    test_script:
      - ctest -C %CONFIGURATION%
    

    【讨论】:

      猜你喜欢
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2014-08-11
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      相关资源
      最近更新 更多