Azure devops AzureDev Ops CI生成未更新版本(VersionPrefix)

Azure devops AzureDev Ops CI生成未更新版本(VersionPrefix),azure-devops,continuous-integration,azure-pipelines,Azure Devops,Continuous Integration,Azure Pipelines,我有一个Azure DevOps管道,带有一个本地nuget包到一个本地工件回购,然后推送到nuget.org 但是,它没有更新版本,并且在本地azure DevOps项目工件中保持在1.0.0-{build\u ver}(同时版本卡在包的build\u ver上) 按预期递增),但当它尝试按nutget键时失败,因为它的版本与1.0.0相同,并忽略项目文件中的1.0.1 请给我任何提示-我如何获得在构建中使用的csproj中定义的版本 我有以下构建yaml: trigger: - master

我有一个Azure DevOps管道,带有一个本地nuget包到一个本地工件回购,然后推送到nuget.org

但是,它没有更新版本,并且在本地azure DevOps项目工件中保持在
1.0.0-{build\u ver}
(同时版本卡在包的build\u 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'
My
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>

netstandard2.0
克里斯托弗·莫利
统一微系统
Unified.Mqtt.Pattern
RangerMuve的mqtt模式快速库的C#端口,用于将mqtt模式与命名通配符匹配,以从主题中提取数据。
https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern
https://github.com/unifiedmicrosystems/Unified.Mqtt.Pattern
github.com
真的
真的
假的
https://www.unifiedmicro.systems/resources/unified-logo.png
许可证
真的
1.0.1
AzureDev Ops CI生成未更新版本(VersionPrefix)

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

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

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack'
  inputs:
    command: pack
    packDirectory: '$(Build.ArtifactStagingDirectory)/packages/prereleases'
    versioningScheme: byBuildNumber
然后,我们可以获得版本为:

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

更新:

我收到错误消息,无法在以下文件中找到版本号数据 环境变量:BUILD\u BUILDNUMBER。我把这个放在哪里?如果…怎么办 我不想要约会,只想要1.0.1

对于
Build.BuildNumber
,我们可以在classic editor中设置它的选项选项卡:

对于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'

希望这能有所帮助。

感谢您的回复,我收到错误消息
在以下环境变量中找不到版本号数据:BUILD\u BUILDNUMBER
。我把这个放在哪里?如果我不想要约会,只想要1.0.1呢?非常感谢。@g18c,对不起,我刚看到你的回复。我已经更新了我的答案,你可以检查一下它是否对你有帮助。谢谢你,利奥,是的,这非常有效。您知道如何设置主要版本、次要版本和构建版本,以便它们来自csproj文件本身吗?@g18c,我们可以在csproj文件中设置构建版本,但这样,我们无法完成自动软件包版本增量。由于我们无法在项目文件中使用
$(Rev:r)
,它属于Azure devops,因此当您打包包时,我们必须手动覆盖包版本,如:
/p:PackageVersion=1.2.3
。查看此文档了解更多详细信息:你好,Leo,感谢您的跟进。我已经更新了这个问题,不确定您是否看到了
任何指针,请-我如何获得在构建中使用的csproj中定义的版本?
换句话说,我如何从
scproj
中提取
1.0.1
,并在
主要
次要
变量中使用它?