Noisy88
Noisy88

Reputation: 183

How can I update the app version by using cicd? (clickonce)

We use a cicd for our WPF project. It's alright but we have one big problem. When cicd deployed a ClickOnce package, then the version of the application didn't change. The application version changes when we make publishing by Visual Studio manually. It isn't great... We use GitLab with a runner. May you advise something?

Upvotes: 2

Views: 1237

Answers (1)

Noisy88
Noisy88

Reputation: 183

Alright. Here is my solution...

I changed that code of my csproj-file:

<ApplicationRevision>123</ApplicationRevision>

to:

<ApplicationRevision Condition=" '$(ver)' != '' ">$(ver)</ApplicationRevision>
<ApplicationRevision Condition=" '$(ver)' == '' ">123</ApplicationRevision>

After that, I changed my .gitlab-ci.yml file:

.myapp-runner:

  before_script:
  - CHCP 65001
  
stages:
  - build
  - cleanup

build_job:
  stage: build
  only:
    - master
  script:
  - $clickonce_ver = [int]${CI_PIPELINE_IID} + 500
  - Write-Host $clickonce_ver
  - '& "C:\tools\nuget.exe" restore myapp.sln -ConfigFile "C:\Users\User\AppData\Roaming\NuGet\NuGet.Config" -source "C:\Users\User\.nuget\packages\;https://www.nuget.org/api/v2/"'
  - '& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" -m -p:Configuration=Release /target:publish -p:cicd=true -p:ver="$clickonce_ver"'
  - '& xcopy .\bin\Release\app.publish\* C:\Publish\ /sy'
  - 'move .\bin\Release\app.publish\ .\artifacts\'
  artifacts:
    expire_in: 1 days
    paths:
        - .\artifacts\

cleanup_job:
  stage: cleanup
  only:
    - master
  script:
  - echo "Сlean up"
  - Remove-Item -Recurse -Force .\*

A CI_PIPELINE_IID variable depends on CI job's number. After each launch, that variable increments.

Application package copies to the C:\Publish\ folder.

Upvotes: 1

Related Questions