gpt4 book ai didi

azure-devops - AzureDev Ops CI 构建未更新版本 (VersionPrefix)

转载 作者:行者123 更新时间:2023-12-02 07:14:38 35 4
gpt4 key购买 nike

我有一个 Azure DevOps 管道,其中包含本地 nuget 包到本地工件存储库,然后推送到 nuget.org。

但是,它不会更新版本,并保留在本地 azure DevOps 项目工件中的 1.0.0-{build_ver}(同时版本卡在包的 build_ver 中) 按预期递增),但是当它尝试推送到 nutget 时,它会失败,因为它的 1.0.0 版本相同,并忽略项目文件中的 1.0.1

请提供任何指示 - 我如何获取构建中使用的 csproj 中定义的版本?

我有以下构建 yaml:

trigger:
- master

stages:

- stage: 'Build'
variables:
buildConfiguration: 'Release'

jobs:
- job:
pool:
vmImage: 'ubuntu-latest'

workspace:
clean: all

steps:
- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
inputs:
packageType: sdk
version: 2.2.x
installationPath: $(Agent.ToolsDirectory)/dotnet

- task: DotNetCoreCLI@2
displayName: "NuGet Restore"
inputs:
command: restore
projects: '**/*.csproj'

- task: DotNetCoreCLI@2
displayName: "Build Solution"
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: "Test Solution"
inputs:
command: test
projects: '**/*Test/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Create NuGet Package - Release Version'
inputs:
command: pack
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/releases'
arguments: '--configuration $(buildConfiguration)'
nobuild: true

- task: DotNetCoreCLI@2
displayName: 'Create NuGet Package - Prerelease Version'
inputs:
command: pack
buildProperties: 'VersionSuffix="$(Build.BuildNumber)"'
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/prereleases'
arguments: '--configuration $(buildConfiguration)'

- publish: '$(Build.ArtifactStagingDirectory)/packages'
artifact: 'packages'



- stage: 'PublishPrereleaseNuGetPackage'
displayName: 'Publish Prerelease NuGet Package'
dependsOn: 'Build'
condition: succeeded()
jobs:
- job:
pool:
vmImage: 'ubuntu-latest'

steps:
- checkout: none

- download: current
artifact: 'packages'

- task: NuGetCommand@2
displayName: 'Push NuGet Package'
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/prereleases/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'Unified.Mqtt.Pattern/Unified.Mqtt.Pattern-Test'



- stage: 'PublishReleaseNuGetPackage'
displayName: 'Publish Release NuGet Package'
dependsOn: 'PublishPrereleaseNuGetPackage'
condition: succeeded()
jobs:
- deployment:
pool:
vmImage: 'ubuntu-latest'
environment: 'nuget-org'
strategy:
runOnce:
deploy:
steps:
- task: NuGetCommand@2
displayName: 'Push NuGet Package'
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/packages/releases/*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'NuGet Unified.Mqtt.Pattern'

我的 csproj 具有以下内容:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Authors>Christopher Morley</Authors>
<Company>Unified Microsystems</Company>
<Copyright />
<PackageId>Unified.Mqtt.Pattern</PackageId>
<Description>C# port of RangerMauve's mqtt-pattern fast library for matching MQTT patterns with named wildcards to extract data from topics.</Description>
<RepositoryUrl>https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</RepositoryUrl>
<PackageProjectUrl>https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern</PackageProjectUrl>
<RepositoryType>github.com</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIconUrl>https://www.unifiedmicro.systems/resources/unified-logo.png</PackageIconUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
<VersionPrefix>1.0.1</VersionPrefix>
</None>
</ItemGroup>
</Project>

最佳答案

Version (VersionPrefix) not being updated by AzureDev Ops CI build

如果要使用$(Build.BuildNumber)更新nuget包版本,任务.NET Core pack任务上有一个Pack选项(显示它与经典编辑器),您可以使用 Build.BuildNumber:

enter image description here

因此,我们可以在 yaml 中使用这个参数,例如:

- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: pack
packDirectory: '$(Build.ArtifactStagingDirectory)/packages/prereleases'
versioningScheme: byBuildNumber

然后,我们就可以得到nuget包的版本:

enter image description here

注意:我看到您的 yaml 文件中有两个 dotnet pack 任务,您应该仔细检查是否需要。

更新:

i get the error Could not find version number data in the following environment variable: BUILD_BUILDNUMBER. Where do i set this? What if i dont want a date, and just want 1.0.1?

对于Build.BuildNumber,我们可以在经典编辑器中设置它的“选项”选项卡:

enter image description here

对于 YAML,您可以在 yaml 文件顶部设置以下内容来实现:

name: 1.0.$(Rev:r)

我们可以使用变量来替换硬代码1.0,例如$(Major).$(Minor).$(Rev:r)

所以,你可以检查我的 YAML 的派对:

name: $(Major).$(Minor).$(Rev:r)

variables:
Major: 1
Minor: 0


pool:
vmImage: 'vs2017-win2016'

希望这有帮助。

关于azure-devops - AzureDev Ops CI 构建未更新版本 (VersionPrefix),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59651660/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com