Search code examples
c#.netbuildappveyor

What is the syntax to use part of the version from CSPROJ and AppVeyor {build} to get a 2.0.x style build number?


Is it possible to have AppVeyor builds use the build number from the csproj file but replace the 'patch' version with the {build} variable?

For Example:

CSPROJ: <Version>2.1.0</Version>
AppVeyor: ??? What goes here? Manually setting 2.1.{build} will work but then to rev to 2.2, we have to update appveyor AND csproj.
Output: 2.1.15 (assuming build number is 15)

Is this possible with the build-in AppVeyor Patching system?


Solution

  • This should work. Just replace subfolder and file name in $xmlPath

    install:
    - ps: |
        $xmlPath = "$env:appveyor_build_folder\mysubfolder\myproject.csproj"
        $xml = [xml](get-content $xmlPath)
        $version = ($xml.Project.PropertyGroup | ? {$_.Version}).Version
        $env:newversion = ($version.Substring(0, $version.LastIndexOf(".") + 1)) + $env:appveyor_build_number
    
    dotnet_csproj:
      patch: true
      file: '**\*.csproj'
      version: $(newversion)
      package_version: $(newversion)
      assembly_version: $(newversion)
      file_version: $(newversion)
      informational_version: $(newversion)