如何在Azure管道中的许多作业之间共享已构建的.NET Core项目?

时间:2019-12-04 08:03:36

标签: c# .net-core azure-devops azure-pipelines .net-core-3.0

- job: buildAndTestJob
 steps:
  - task: DotNetCoreCLI@2
    displayName: dotnet restore
    inputs:
      command: restore
      vstsFeed:  $(vstsFeed)
  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      arguments: '--configuration ${{ parameters.buildConfiguration }}'
  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: test
      arguments: '--configuration ${{ parameters.buildConfiguration }}'
  - task: CopyFiles@2
    displayName: copy bin files
    inputs:
      sourceFolder: '$(Build.SourcesDirectory)'
      contents: '**/bin/**/*'
      TargetFolder: '$(Build.ArtifactStagingDirectory)'
  - task: CopyFiles@2
    displayName: copy obj files
    inputs:
      sourceFolder: '$(Build.SourcesDirectory)'
      contents: '**/obj/**/*'
      TargetFolder: '$(Build.ArtifactStagingDirectory)'
  - task: PublishBuildArtifacts@1
    displayName: publish build artifacts
    inputs:
      pathtoPublish: '$(Build.ArtifactStagingDirectory)'
      artifactName: buildeffect
      publishLocation: 'Container'


-job: packAndPushJob
  steps:
  - task: DownloadBuildArtifacts@0
    displayName: download build artifacts
    inputs:
      buildType: 'current'
      downloadType: 'single'
      artifactName: 'buildeffect'
      downloadPath: '$(Build.ArtifactStagingDirectory)'
  - task: CopyFiles@2
    displayName: copy files to source directory
    inputs:
      sourceFolder: '$(Build.ArtifactStagingDirectory)/buildeffect'
      contents: '**/*'
      TargetFolder: '$(Build.SourcesDirectory)'
      allowPackageConflicts: true
  - task: DotNetCoreCLI@2
    displayName: 'dotnet pack'
    inputs:
      arguments: '--no-restore'
      nobuild: true
      command: pack
      projects: '$(Build.SourcesDirectory)'
      publishWebProjects: true
      publishVstsFeed: $(vstsFeed)
      includeNuGetOrg: true
  - task: NuGetCommand@2
    displayName: 'nuGet push'
    inputs:
      command: push
      projects: '$(Build.SourcesDirectory)'
      publishVstsFeed: $(vstsFeed)
      allowPackageConflicts: true

我有2个工作。首先,要在构建工件中还原,测试,构建和共享构建文件。其次打包和推送nuget程序包。第一项工作成功完成了他们的工作,但是第二项工作在打包任务期间失败了。 nuget软件包有问题,例如:

/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.CSharp, version 4.6.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/home/vsts/work/1/s/src/Spotio.Leads.Client/Spotio.Leads.Client.csproj]

那么,也许我们应该以另一种方式共享构建的项目?还是在供稿中添加一些参数以恢复?我没有任何想法,所以,如果您有任何建议,请帮助我们:)

1 个答案:

答案 0 :(得分:0)

  

如何在Azure中的许多作业之间共享一个已构建的.NET Core项目   管道?

1。请参见this:使用PackageReference格式的项目始终直接使用此文件夹(%userprofile%\.nuget\packages)中的程序包。

2。以.net core为目标的项目使用PackageReference格式,因此还原的软件包存储在{strong.firstagent 中的%userprofile%\.nuget\packages中。

3。对于您的第二个代理商任务,开发人员实际上会启动另一个托管代理来运行任务。这意味着对于第二个代理商,它在%userprofile%\.nuget\packages中没有引用的软件包。

4。我们应该知道的是:尽管我们已将binobj的所有文件复制到第二个代理商,但是dotnet pack xx.csproj仍会尝试确认引用的程序包存在,然后发生此问题。

因此,我建议您在第二个代理程序作业中的dotnet restore任务之前添加一个dotnet pack任务,以确保可以在第二个代理程序中找到丢失的软件包

注意:

1。在具有两个代理作业的一个构建管道中,尽管这两个代理作业均使用托管代理,但这两个代理不是同一实例。

2。确保用于构建的配置与用于打包的配置相同。

希望有帮助。如果我误解了,请随时告诉我:)

相关问题