Azure构建任务-从所有解决方案中仅构建一个项目

时间:2020-10-06 20:01:34

标签: azure azure-devops

我在ci / cd中遇到天蓝色任务的问题, 每个发行版都有一个测试任务,该任务在部署代码之前以及每次构建所有解决方案时都需要运行。 我只希望构建与发行版相关的特定项目,而不是所有解决方案。 我该如何解决?

2 个答案:

答案 0 :(得分:1)

根据您的SO标签,看来您正在使用C#。

  • 要在构建任务中构建一个针对.net framework的特定项目:

    您应该使用MSBuild task而不是Visual Studio Build task

    enter image description here

  • 要在构建任务中构建一个针对.net core/standard的特定项目:

    您应在此类输入中使用Dotnet build

    enter image description here

  • 此外,如果您在发布任务中使用Dotnet测试,它将自动构建要测试的项目,除非您添加--no-build开关。因此,您还需要确保指定要测试的特定项目,而不是使用**/*.csproj

    enter image description here

答案 1 :(得分:0)

trigger:
  branches:
    include:
    - master
    
pool:
  name: Azure Pipelines
  vmImage: 'windows-2019'
  demands:
    - msbuild
    - visualstudio

variables: 
  BuildConfiguration: "Release"
  platform: any cpu
  BuildPlatform: any cpu

name: 1.$(build.buildid)

stages:
- stage: Build
  jobs:
  - job: Build  
    steps:
    - task: NuGetToolInstaller@0
      displayName: 'Use NuGet 4.4.1'
      inputs:
        versionSpec: 4.4.1
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: 'path to sln file/xxxxxxx.sln'
        vstsFeed: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'        
    - task: VSBuild@1
      displayName: 'Build solution'
      inputs:
        solution: 'path to sln file/xxxxxxx.sln'
        platform: '$(BuildPlatform)'
        configuration: '$(BuildConfiguration)'
        clean: true

此外,如果选择了相应的sln文件,请在初始步骤中检查管道 enter image description here