如何在 Azure 管道中的多个作业之间共享构建的 .NET Core 项目?
How can I share a built .NET Core project between many jobs in Azure pipelines?
- 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]
那么,也许我们应该以另一种方式共享构建的项目?或者可能添加一些带有提要的参数来恢复?我不知道,所以如果您有任何建议,请帮助我们:)
How can I share a built .NET Core project between many jobs in Azure
pipelines?
1.See this : 使用 PackageReference
格式的项目总是使用直接来自该文件夹的包 (%userprofile%\.nuget\packages
).
2.Project targets .net core
使用 PackageReference
格式,所以恢复包存储在 %userprofile%\.nuget\packages
in first agent .
3.For 你的 第二个代理工作 ,devops 实际上开始 另一个 托管代理来 运行 你的任务。这意味着 第二个代理 ,它没有 %userprofile%\.nuget\packages
.
中引用的包
4.Something 我们应该知道的是:虽然我们已经将 bin
和 obj
的所有文件复制到 第二个代理 ,dotnet pack xx.csproj
仍然会尝试确认引用的包是否存在,然后就会出现问题。
所以我建议您可以在第二个代理作业中的dotnet pack
任务之前添加一个dotnet restore
任务,以确保可以在中找到丢失的包二级代理.
注:
1.In一个构建管道有两个代理作业,虽然这两个代理作业都使用托管代理,但这两个代理不是同一个实例。
2.Make确保您用于构建的配置与您用于打包的配置相同。
希望对您有所帮助。如果我有任何误解,请随时告诉我:)
- 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]
那么,也许我们应该以另一种方式共享构建的项目?或者可能添加一些带有提要的参数来恢复?我不知道,所以如果您有任何建议,请帮助我们:)
How can I share a built .NET Core project between many jobs in Azure pipelines?
1.See this : 使用 PackageReference
格式的项目总是使用直接来自该文件夹的包 (%userprofile%\.nuget\packages
).
2.Project targets .net core
使用 PackageReference
格式,所以恢复包存储在 %userprofile%\.nuget\packages
in first agent .
3.For 你的 第二个代理工作 ,devops 实际上开始 另一个 托管代理来 运行 你的任务。这意味着 第二个代理 ,它没有 %userprofile%\.nuget\packages
.
4.Something 我们应该知道的是:虽然我们已经将 bin
和 obj
的所有文件复制到 第二个代理 ,dotnet pack xx.csproj
仍然会尝试确认引用的包是否存在,然后就会出现问题。
所以我建议您可以在第二个代理作业中的dotnet pack
任务之前添加一个dotnet restore
任务,以确保可以在中找到丢失的包二级代理.
注:
1.In一个构建管道有两个代理作业,虽然这两个代理作业都使用托管代理,但这两个代理不是同一个实例。
2.Make确保您用于构建的配置与您用于打包的配置相同。
希望对您有所帮助。如果我有任何误解,请随时告诉我:)