【问题标题】:Azure Pipelines multi project and platform buildAzure Pipelines 多项目和平台构建
【发布时间】:2020-05-25 00:25:06
【问题描述】:

我有通过 Azure Pipelines 构建的复杂 C# 解决方案。

这是一个 MonoGame v3.7.1 项目,其中包含我在公共 GitHub 存储库中托管的多个项目。解决方案结构如下所示:

- AzureTest
    - AzureTest.Core
    - AzureTest.DirectX
    - AzureTest.OpenGL

Core 项目是共享项目,无法运行,而 DirectX 和 OpenGL 都引用了 .Core,可以运行。所有游戏代码都将存在于 Core 项目中。

我当前的 azure-pipelines.yml 配置文件如下所示:

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
  branches:
    include:
    - '*'

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'x86'
  buildConfiguration: 'Release'
  monoGameVersion: 'v3.7.1'

steps:
- task: GitVersion@5
  inputs:
    runtime: 'full'
    updateAssemblyInfo: true
    configFilePath: 'gitversion.yml'

- script: |
    powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://github.com/MonoGame/MonoGame/releases/download/$(monoGameVersion)/MonoGameSetup.exe', '.\MonoGameSetup.exe')"
  displayName: 'Download MonoGame $(monoGameVersion)'

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: 'MonoGameSetup.exe'
    destinationFolder: './tmp/'
  displayName: 'Extract MonoGame $(monoGameVersion)'

- script: |
    mkdir "%PROGRAMFILES(X86)%\MSBuild"
    xcopy .\tmp\$PROGRAMFILES\MSBuild "%PROGRAMFILES(X86)%\MSBuild" /E /Y
    mkdir "%PROGRAMFILES(X86)%\MonoGame\v3.0\Assemblies\"
    xcopy .\tmp\Assemblies "%PROGRAMFILES(X86)%\MonoGame\v3.0\Assemblies" /E /Y
  displayName: 'Install MonoGame $(monoGameVersion)'

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

这会下载指定版本的 MonoGame,解压并安装它(我从this article 找到了配置)。可以理解的是,这只会构建解决方案中设置为启动项目的任何项目。我也在使用 GitVersion 进行自动版本控制,配置文件如下所示:

mode: Mainline
branches: {}
ignore:
  sha: []

我想运行一个管道作业/任务/阶段,在 Windows 下构建 DirectX 项目,在 Windows、MacOS 和 Linux 下构建 OpenGL 项目,并可能为每个构建创建工件,尽管我没有研究工件然而。我对使用 Azure Pipelines 很陌生,所以我不确定是否应该为每个平台/项目创建单独的 azure-pipeline.yml 文件,或者是否可以在单个管道配置中定义平台配置。

【问题讨论】:

  • 我最近没有机会做这个。我需要创建一个工作镇下载并安装适用于 MacOS 和 Linux 的 MonoGame。

标签: c# azure azure-devops azure-pipelines monogame


【解决方案1】:

所以我不确定是否应该为每个平台/项目创建单独的 azure-pipeline.yml 文件,或者是否可以在单个管道配置中定义平台配置。

答案是肯定的。您可以将多个作业与多个代理并行使用,例如:

jobs:
- job: Windows
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - script: echo hello from Windows
- job: macOS
  pool:
    vmImage: 'macOS-10.14'
  steps:
  - script: echo hello from macOS
- job: Linux
  pool:
    vmImage: 'ubuntu-16.04'
  steps:
  - script: echo hello from Linux

因此,我们可以在job1中使用Windows代理构建DirectX项目,并在job2job3job4中使用相应的代理构建Windows、MacOS和Linux下的OpenGL项目。

注意:如果你在几个job之间有优先顺序,请注意使用dependsOn:

您可以查看文档Specify jobs in your pipeline的详细信息。

希望这会有所帮助。

【讨论】:

  • 感谢您的回答,这为我指明了正确的方向。我对如何从每个工作内部开始构建有点困惑。我已将配置文件中的步骤复制到每个作业的步骤中。这适用于 Windows,但我需要更改 Mac 和 Linux 的下载步骤。
  • 这个和你项目的具体流程有关。如果在winodws下生成文件并在Mac和Linux上处理,需要使用Download Build Artifacts任务下载Build Artifacts任务:docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/…
猜你喜欢
  • 2019-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 2019-10-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多