Azure Dev Ops:将 .NET 构建为 Release

时间:2021-03-18 22:46:35

标签: docker azure-devops azure-pipelines

我有以下 azure 管道,但它似乎是作为调试版本构建的。 我知道这一点是因为代码中有一些“#if DEBUG”并且它在使用管道构建的应用程序中也处于活动状态。

我正在寻找一种调试方法以及一些文档。

如果有人有调试或更好地修复它的想法,欢迎您。

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/MyProd.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

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

- task: Npm@1
  inputs:
    command: 'install'
    workingDir: 'src/MyCorp.Core.Blazor'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '$(solution)'
    arguments: ''

- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '$(solution)'

- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.httpapi'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.HttpApi.Host/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'

- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.identityserver'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.IdentityServer.Host/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'

- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.Web'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.Web/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'

- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.jobs'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.Jobs.Host/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'
    
- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.imageai.jobs'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.Jobs.ImageAI.Host/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'

- task: Docker@2
  inputs:
    containerRegistry: 'myprod'
    repository: 'myuser/myprod/myprod.dbmigrator'
    command: 'buildAndPush'
    Dockerfile: 'src/MyProd.DbMigrator/Dockerfile'
    buildContext: '$(Build.SourcesDirectory)'
    tags: '1.1.$(Build.BuildId)'

1 个答案:

答案 0 :(得分:0)

您的意思是您将 buildConfiguration 配置为 release 但它通过 debug 运行构建,对吗?

检查任务.NET Core build,我们需要添加参数--configuration $(buildConfiguration),然后它将构建.NET作为发布而不是调试

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(solution)'
    arguments: '--configuration $(buildConfiguration)'