You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启用ReadyToRun时Azure DevOps Pipelines发布.NET项目报401错误

问题:Azure DevOps中Release模式启用ReadyToRun发布.NET项目时出现401授权错误

我们正尝试在Azure DevOps中以Release模式发布启用ReadyToRun的.NET项目,该项目依赖另一个共享库项目的构件。每次执行dotnet publish命令时都会抛出大量401授权错误,但Debug模式下发布或未启用ReadyToRun时无此问题。

微软技术支持认为这是授权问题,但由于未启用ReadyToRun时可正常获取构件,该结论并不合理。

当前Pipeline配置

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- main

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  publish.buildConfiguration: 'Publish'
  publish.path: '$(System.DefaultWorkingDirectory)\publish\'
  publish.artifactFolderName : 'Packages'
  
  #App API
  projectName.appApi: 'Linak.Deskline.Tracking.AppApi'
  projectPath.appApi: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.AppApi\$(projectName.appApi).csproj'
  ressource.dev.function.appApi: 'func-dtr-app-weu-dev-01'
  ressource.tst.function.appApi: 'func-dtr-app-weu-tst-01'
  ressource.prod.function.appApi: 'func-dtr-app-weu-prod-01'

  #Integrator API
  projectName.integratorApi: 'Linak.Deskline.Tracking.integratorApi'
  projectPath.integratorApi: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.IntegratorApi\$(projectName.integratorApi).csproj'
  ressource.dev.function.integratorApi: 'func-dtr-integrator-weu-dev-01'
  ressource.tst.function.integratorApi: 'func-dtr-integrator-weu-tst-01'
  ressource.prod.function.integratorApi: 'func-dtr-integrator-weu-prod-01'

  #LipDataHandler Api
  projectName.lipDataHandler: 'Linak.Deskline.Tracking.LipDataHandler'
  projectPath.lipDataHandler: '.\Sources\Linak.Deskline.Tracking\Linak.Deskline.Tracking.LipDataHandler\$(projectName.lipDataHandler).csproj'  
  ressource.dev.function.lipDataHandler: 'func-dtr-lipevents-weu-dev-01'
  ressource.tst.function.lipDataHandler: 'func-dtr-lipevents-weu-tst-01'
  ressource.prod.function.lipDataHandler: 'func-dtr-lipevents-weu-prod-01'

stages: 
- stage: Build
  jobs: 
  - job: BuildAndPublishZips
    displayName: Build and publish zip files
    steps:
    
    - task: NuGetToolInstaller@1
      displayName: 'Get Nuget'

    - task: NuGetCommand@2
      displayName: 'Nuget Restore'
      inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        feedsToUse: 'config'
        nugetConfigPath: '.\Sources\Linak.Deskline.Tracking\nuget.config'
        arguments: '--runtime win-x86'

    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.appApi)'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.appApi)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.integratorApi) '
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.integratorApi)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'
      
    - task: DotNetCoreCLI@2
      displayName: 'Build and publish - $(projectName.lipDataHandler)'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '$(projectPath.lipDataHandler)'
        arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'
      
    - task: DotNetCoreCLI@2
      displayName: 'Run tests'
      inputs:
        command: 'test'
        projects: '**\*.csproj'
        testRunTitle: 'Deskline Cloud Test'

    - task: PublishPipelineArtifact@1
      displayName: 'Publishing deploy packages'
      inputs:
        targetPath: '$(publish.path)'
        artifact: '$(publish.artifactFolderName)'
        publishLocation: 'pipeline'

#DEV
- stage: Deploy_DEV
  dependsOn: Build
  jobs: 
  - deployment: Deploy_DEV
    displayName: 'Deploy to DEV'
    environment: 'Tracking - DEV'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                # Write your PowerShell commands here.
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Development'
              appType: 'functionApp'
              appName: $(ressource.dev.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'
#TEST
- stage: Deploy_TEST
  dependsOn: 'Deploy_DEV'
  jobs: 
  - deployment: Deploy_TEST
    displayName: Deploy to TEST
    environment: 'Tracking - TEST'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy TEST - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy TEST - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy DEV - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Test'
              appType: 'functionApp'
              appName: $(ressource.tst.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'
#PROD
- stage: Deploy_PROD
  dependsOn: 'Deploy_TEST'
  jobs: 
  - deployment: Deploy_PROD
    displayName: Deploy to PROD
    environment: 'Tracking - PROD'
    strategy:
      runOnce:
        deploy:
          steps: 
          - task: PowerShell@2  
            displayName: "List build artifacts"
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)"
                cd $(Agent.BuildDirectory)/$(publish.artifactFolderName)
                dir   
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.integratorApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.integratorApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.integratorApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.appApi)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.appApi)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.appApi).zip'
              deploymentMethod: 'zipDeploy'
          - task: AzureFunctionApp@1
            displayName: 'Deploy PROD - $(projectName.lipDataHandler)'
            inputs:
              azureSubscription: 'Deskline Cloud - Production'
              appType: 'functionApp'
              appName: $(ressource.prod.function.lipDataHandler)
              package: '$(Agent.BuildDirectory)/$(publish.artifactFolderName)/$(projectName.lipDataHandler).zip'
              deploymentMethod: 'zipDeploy'

错误发生步骤

- task: DotNetCoreCLI@2
  displayName: 'Build and publish - $(projectName.appApi)'
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '$(projectPath.appApi)'
    arguments: '-o $(publish.path) /bl -c $(publish.buildConfiguration)'

已尝试的解决方案

  • 在publish命令中添加-no-restore参数
  • 在Pipeline中添加指定.NET Core SDK版本的步骤:
    steps:
    - task: UseDotNet@2
      displayName: 'Use .NET Core sdk 6.0.x'
      inputs:
        version: 6.0.x
    
  • 确保出现授权失败的构建服务拥有共享库构件的访问权限

微软已有多位技术人员处理该问题但未取得进展,特此寻求可行的解决方案。


内容的提问来源于stack exchange,提问作者Lukas Méndez Duus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 20:45:49