如何从 AppVeyor 发布 beta nuget 包 [英] How to publish beta nuget packages out of AppVeyor

查看:59
本文介绍了如何从 AppVeyor 发布 beta nuget 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试图在 AppVeyor 中实现的行为

Here is the behavior I'm trying to achieve in AppVeyor

  1. 构建代码(用 1.2.3.{build} 标记 AssemblyInfo)
  2. 测试代码
  3. 如果测试通过,则创建 nuget 包
  4. 如果包创建成功,则发布测试包 (1.2.3-beta-{build})
  5. 还要在工件中提供包.
  1. Build the code (stamp AssemblyInfo with 1.2.3.{build})
  2. Test the code
  3. Create the nuget package if the tests passed
  4. Publish the beta package if the package created successfully (1.2.3-beta-{build})
  5. Also make the package available in artifacts.

理想情况下,在发布 nuget 包时,它将作为预发布版本发布.在 NuGet 中,这是通过在包版本的末尾添加字母字符来完成的.覆盖现有包也被认为是不好的做法(实际上,许多 nuget 实现不允许这样做).

Ideally when publishing a nuget package it would be published as prerelease. In NuGet, this is done by adding alpha characters to the end of the package version. It is also considered bad practice to overwrite an existing package (indeed, many nuget implementations do not allow this).

AppVeyor 在用 github 构建和测试软件方面做得很好,但我似乎无法控制 nuget 包版本.

AppVeyor does a good job of building and testing software out of github, but I don't seem to be able to control the nuget package version.

给定:下一个语义版本 1.2.3 的包我希望 AppVeyor {version} 变量等于 1.2.3.{build}我希望 nuget 包版本等同于 1.2.3-beta-{build}

Given: A package with the next semantic version of 1.2.3 I would expect the AppVeyor {version} variable to equate to 1.2.3.{build} I would expect the nuget package version to equate to 1.2.3-beta-{build}

我尝试的第一件事是在 {version} 框中使用变量.显然这是不允许的.AppVeyor 似乎只对 {branch}{build} 进行变量替换,作为 {version} 的一部分.这意味着我必须为语义版本维护一个单独的变量.

The first thing I tried was using variables in the {version} box. Apparently this is not allowed. AppVeyor seems to only do variable substitution for {branch} and {build} as part of the {version}. This means I'll have to maintain a separate variable for the semantic version.

我遇到的下一个挑战是无法通过 UI 设置 nuget 包版本.它希望默认与 AppVeyor 构建版本相同.

The next challenge I ran into is that there's no way to set the nuget package version through the UI. It wants to default to be the same as the AppVeyor build version.

我决定在测试运行后尝试使用 Powershell 创建包.这有效,但 Nuget Publish 步骤希望在创建包之前运行,并且似乎没有办法控制执行顺序.

I decided to try creating the package using Powershell after the tests run. This works, but the Nuget Publish step wants to run before the package is created and there doesn't seem to be a way to control the execution order.

我想我走错了路.我需要一个概念重置.

I think I'm on the wrong track. I need a conceptual reset.

这是我的 appveyor.yml 当前(不正确)状态:

Here is my appveyor.yml in its current (incorrect) state:

version: 0.1.0.{build}
configuration: Release
assembly_info:
  patch: true
  file: '**\AssemblyInfo.*'
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'
environment:
  packageVersion: 0.1.0
nuget:
  account_feed: true
  project_feed: true
  disable_publish_on_pr: true
before_build:
- ps: nuget restore
build:
  verbosity: minimal
artifacts:
- path: '*.nupkg'
  name: nuget package
deploy:
- provider: NuGet
  api_key:
    secure: blahblahblah
  artifact: '*.nupkg'
  on:
    branch: master
on_success:
- ps: >-
    $releaseVersion= $env:packageVersion

    $buildNumber = $env:APPVEYOR_BUILD_NUMBER

    $betaVersion= "$releaseVersion-beta-$buildNumber"

    nuget pack Odin.nuspec -version $betaVersion

    Get-ChildItem .\*.nupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

我该如何解决这个问题?我能得到我想要的行为吗?

How do I fix this? Can I get the behavior I want?

推荐答案

您可以使用 PowerShell 和 AppVeyor API 来控制版本号.我会尝试编写 appveyor.yml 如下:

You can use PowerShell and AppVeyor API to control version number. I would try composing appveyor.yml as following:

version: 0.1.0.{build}

environment:
  packageVersion: 0.1.0

init:
- ps: $env:buildVersion = "$env:packageVersion.$env:appveyor_build_number"
- ps: $env:nugetVersion = "$env:packageVersion-beta-$env:appveyor_build_number"
- ps: Update-AppveyorBuild -Version $env:buildVersion

assembly_info:
  patch: true
  file: '**\AssemblyInfo.*'
  assembly_version: '$(buildVersion)'
  assembly_file_version: '$(buildVersion)'
  assembly_informational_version: '$(nugetVersion)'

configuration: Release

nuget:
  account_feed: true
  project_feed: true
  disable_publish_on_pr: true

before_build:
- nuget restore

build:
  verbosity: minimal

after_build:
- nuget pack Odin.nuspec

artifacts:
- path: '*.nupkg'

deploy:
- provider: NuGet
  api_key:
    secure: blahblahblah
  artifact: '*.nupkg'
  on:
    branch: master

这篇关于如何从 AppVeyor 发布 beta nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆