azure-devops - 在一个管道中构建项目并创建 NuGet 包
问题描述
我在 C# 中有一个带有 2 个类库的解决方案。
我在 Azure DevOps 中有一个构建和发布一个 NuGet 包的管道,它正在工作。YAML 是
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- task: DotNetCoreCLI@2
displayName: Restore packages
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
displayName: Build project
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: Run tests
inputs:
command: 'test'
projects: '**/*[Te]ests/*.csproj'
- task: NuGetCommand@2
displayName: Prepare the package
inputs:
command: 'pack'
packagesToPack: '**/*.csproj'
versioningScheme: 'byEnvVar'
versionEnvVar: 'PackageVersion'
- task: NuGetCommand@2
displayName: Push the package
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'xxx'
当我有 2 个项目时,这个管道失败了。我注意到在构建步骤中,项目是在一个Debug
文件夹中创建的。
在“准备包”中,管道正在Azure DevOps的文件夹中搜索.dll 。Release
然后,我有几个问题:
- 是否可以使用相同的管道创建和发布多个包?
- 我正在使用 Visual Studio 2021,但尚未创建任何.nuspec。我必须创建它们吗?
- 为什么 Azure DevOps 使用 2 个不同的文件夹进行构建和打包?我是否必须将不同的文件夹作为参数传递?
解决方案
所以你应该提供--configuration Release
你的构建步骤。由于您没有提供它,因此将 Debug 视为默认值,并将 Release 视为默认值。
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
displayName: Restore packages
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: '**/*.csproj'
displayName: 'dotnet build $(buildConfiguration) --no-restore'
- task: DotNetCoreCLI@2
inputs:
command: test
projects: '**/*[Te]ests/*.csproj'
arguments: '--configuration $(buildConfiguration) --no-build'
- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: 'pack'
projects: '**/*.csproj'
arguments: '-o $(Build.ArtifactStagingDirectory)/Output --no-build'
versioningScheme: 'byEnvVar'
versionEnvVar: 'PackageVersion'
- task: DotNetCoreCLI@2
displayName: "Publish packages"
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/Output/*.*nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'guid'
回答您的其他问题:
是否可以使用相同的管道创建和发布多个包?
是的
我正在使用 Visual Studio 2021,但尚未创建任何 .nuspec。我必须创建它们吗?
不
推荐阅读
- python - django.db.utils.IntegrityError: NOT NULL 约束失败。哪里的约束不被尊重?
- reporting-services - SSRS 2012 Reporting Services 并行数据集检索
- zendesk - 在 Zendesk 中创建工单
- javascript - 角度 4:无法读取类变量的属性
- c# - vs2017联动realsense摄像头
- javascript - 为什么我在使用我的功能时得到[本机代码]
- php - 如何在php上插入逻辑工作
- matlab - Matlab跳跃图(不确定性)
- api - Asp.Net Core Web Api 中的自定义授权
- html - Safari 使用 rem 和动画的大小不正确