azure-devops - ## [错误]在以下环境变量: BUILD_BUILDNUMBER中找不到版本号数据

标签 azure-devops nuget azure-pipelines azure-pipelines-build-task

我正在使用以下yaml生成我的NuGet pkg。我想为包裹添加唯一的ID和日期。但我不断收到错误消息,说无法在以下环境变量中找到版本号数据:BUILD_BUILDNUMBER

##[error]Could not find version number data in the following environment variable: BUILD_BUILDNUMBER. The value of the variable should contain a substring with or are positive integers.



我尝试使用名称:$(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r)byBuildNumber verisonScheme nuget pack需要此名称。

还尝试将BUILD_BUILDNUMBER设置为yaml文件中的变量。
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

name: $(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r) # need this for byBuildNumber verisonScheme nuget pack
# the build will trigger on any changes to the master branch
trigger:
- master

# the build will run on a Microsoft hosted agent, using the lastest Windows VM Image
pool:
  vmImage: 'windows-latest'

# these variables are available throughout the build file
# just the build configuration is defined, in this case we are building Release packages
variables:
  buildConfiguration: 'Release'


#The build has 3 seperate tasks run under 1 step
steps:
# The first task is the dotnet command build, pointing to our csproj file
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
    projects: 'src/Repository.sln'

# The second task is dotnet pack command again pointing to the csproj file
# The nobuild means the project will not be compiled before running pack, because its already built in above step
- task: DotNetCoreCLI@2
  displayName: "dotnet pack"
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: 'src/Common.Core/Common.Core.csproj'
    nobuild: true
    includeSymbols: true
    versioningScheme: 'byBuildNumber'


# The last task is a nuget command, nuget push
# This will push any .nupkg files to the 'Nuget' artifact feed
# allowPackageConflicts allows us to build the same version and not throw an error when trying to push
# instead it just ingores the latest package unless the version changes
- task: NuGetCommand@2
  displayName: 'nuget push'
  inputs:
    command: 'push'
    feedsToUse: 'select'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'MyNuget'
    allowPackageConflicts: true



我希望它会生成具有正确版本号的nuget,而不会导致nuget pack步骤失败。

最佳答案

当您选择NuGet软件包的版本将类似于内部版本号时,您不能将此值$(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r)赋予内部版本号。

应采用以下格式:
$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

您可以在经典编辑器中看到此信息:

enter image description here

您可以在docs中找到更多信息:

对于 byPrereleaseNumber ,版本将设置为您为主要,次要和补丁选择的任何版本,以及日期和时间,格式为yyyymmdd-hhmmss。

对于EnvVar 的,版本将设置为任何环境变量,例如您提供的是MyVersion(没有$,只有环境变量名称)。确保将环境变量设置为适当的SemVer,例如1.2.3或1.2.3-beta1。

对于 byBuildNumber ,版本将设置为内部版本号,请确保您的内部版本号是正确的SemVer例如。 1.0。$(Rev:r)。如果选择byBuildNumber,则该任务将提取一个带点缀的版本1.2.3.4,并仅使用该版本,并删除所有标签。要按原样使用内部版本号,您应该如上所述使用byEnvVar,并将环境变量设置为BUILD_BUILDNUMBER。

关于azure-devops - ## [错误]在以下环境变量: BUILD_BUILDNUMBER中找不到版本号数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57797140/

相关文章:

git - Azure DevOps Pipeline 不会根据另一个分支触发

c# - 如何在发布服务器项目而不是客户端的 Azure DevOps 上为 Blazor WebAssembly 托管应用程序创建构建管道?

c# - Microsoft.CSharp.Core.targets 缺失

visual-studio - NuGet软件包管理器: "No packages found" even though the package exists

Azure Pipelines 代理代理设置未按预期工作

node.js - Azure DevOps 自定义任务扩展 : powershell. exe/node.exe 退出代码:5

ios - 无法在Azure Devops中导出IPA文件

VSTS 上的 Docker-compose

azure - 如何将 Azure Pipeline 测试结果链接到测试用例

nuget - Artifactory NuGet 安装未获取最新的软件包版本