.nu​​spec文件中的Azure DevOps管道变量 [英] Azure DevOps pipeline variables in .nuspec files

查看:117
本文介绍了.nu​​spec文件中的Azure DevOps管道变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在用于包创建的.nuspec文件中使用Azure DevOps管道变量?

Is it possible to use Azure DevOps pipeline variables in .nuspec files, which are used for packages creation?

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>MyTemplate</id>
    <version>$(var1).$(var2).$(var3)</version>
    <description>
      Some template
    </description>
    <authors>Test Test</authors>
    <packageTypes>
      <packageType name="Template" />
    </packageTypes>
  </metadata>
</package>

或者这是.yaml任务中的那些人获取.nuspec文件中指定的ovveride版本的一种方法(必填元素)?

Or is it a way to ovveride version specified in .nuspec file(it is required element) by those one in .yaml task?

task: NuGetCommand@2
  displayName: Pack template
  inputs:
    command: pack
    packagesToPack: '**/Template/*.nuspec'
    packDestination: $(Build.ArtifactStagingDirectory)
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(var1)'
    minorVersion: '$(var2)'
    patchVersion: '$(var3)'

但是使用versioningScheme:byPrereleaseNumber,我们会将时间戳添加到我们的数字中.

But with versioningScheme: byPrereleaseNumber we will get timestamp added to our numbers.

推荐答案

用于构建属性的弹出式工具提示:

Pop-up ToolTip for Build Properties:

指定由分号分隔的令牌=值对的列表,其中.nuspec文件中每次出现的$ token $都将替换为给定值.值可以是带引号的字符串.

Specifies a list of token=value pairs, separated by semicolons, where each occurrence of $token$ in the .nuspec file will be replaced with the given value. Values can be strings in quotation marks.

通过进入UI构建器以可视化地编辑管道,我发现了以下YAML,在NuGet > Pack任务内部有一个高级"窗格.它允许您在构建属性"(buildProperties)下指定其他令牌替换值

I figured out the following YAML by going into the UI builder for editing the pipeline visually, there's an "Advanced" pane inside the NuGet > Pack task. It allows you to specify additional token replacement values under "build properties" (buildProperties)

我觉得这是您必须将一种类型的令牌转换为另一种类型的令牌之一..请参阅最后一行的buildProperties:

I have a feeling it's one of those things where you have to transform one type of token into another.. see the buildProperties on the last line:

variables:
  Parameters.requestedMajorVersion: '1'
  Parameters.requestedMinorVersion: '0'
  Parameters.requestedPatchVersion: '6'

steps:
- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    packagesToPack: '**/*.nuspec'
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(Parameters.requestedMajorVersion)'
    minorVersion: '$(Parameters.requestedMinorVersion)'
    patchVersion: '$(Parameters.requestedPatchVersion)'
    includeSymbols: true
    buildProperties: 'id=$(Build.Variable)'

.nuspec示例

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata minClientVersion="2.5">
    <id>$id$</id>

这篇关于.nu​​spec文件中的Azure DevOps管道变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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