Azure Devops - parse version into .nuspec file

751 Views Asked by At

How can I parse the specified version from the .yaml file to the .nuspec file?

Here are the important parts of the .yaml file

variables:
    solution: '**/*.csproj'
    buildPlatform: 'Any CPU'
    buildConfiguration: 'Release'
    version.MajorMinor: '1.0'
    version.Revision: $[counter(variables['version.MajorMinor'], 0)]
    versionNumber: '$(version.MajorMinor).$(version.Revision)'

steps:
- task: DotNetCoreCLI@2
    displayName: '$(buildConfiguration)'
    inputs:
        command: 'pack'
        packagesToPack: '**/*.nuspec'
        versioningScheme: 'byEnvVar'
        versionEnvVar: 'versionNumber'

.nuspec file

<?xml  version="1.0" ?>
<package>
    <metadata>
        <id>Project</id>
        <version>0.0.1</version>
        <description>Project description</description>
        <authors>Me</authors>
    </metadata>

    <files>
        <file  src="bin\**\*.dll"  target="lib"  />
    </files>
</package>

I'm using the .nuspec file so that I can include some other .dlls in the NuGet package. How can I parse the versionNumber variable to the .nuspec file using DotNetCoreCLI@2 task?

1

There are 1 best solutions below

0
Dmitry On

You can use XmlTransformV1@0 task to override versionNumber in your Pipeline:

https://marketplace.visualstudio.com/items?itemName=dzhukovsky.xml-transform

Build defenition:

- task: XmlTransformV1@0
  inputs:
    folderPath: '**/*.nupkg'
    targetFiles: '*.nuspec'
    overrides: 'package.metadata.version = 1.2.3' 

Release definition:

enter image description here