Search code examples
c#.netclickoncemage

How do I detect updates with a manually deployed ClickOnce using mage?


So I followed the instructions here for manually deploying a clickonce application and I finally got things to work, but after incrementing the revision number and redeploying, I found that launching the installed application does not automatically update itself to the newest version. Currently, my deployed folder structure is like this:

  • foo.application
  • Foo
    • foo.exe
    • foo.exe.manifest

What am I missing to have it automatically update itself similar to a ClickOnce publish from Visual Studio?


Solution

  • I figured it out. Turns out that you have to do a few things different here:

    1. You cannot just generate a new deployment file each time. You have to update your existing one.
    2. You have to manually set the <beforeApplicationStartUp /> node since mage does not support this setting.

    So what I ended up doing was first checking my remote deployment directory to see if I already have a deployment manifest, and if I did, I'd copy it over to my build server and call mage -Update and supply the new version number with -Version. To force the update instead of prompting, you have to also supply -MinVersion and set it to the same value as -Version. Before signing the updated deployment (or the first one if you haven't already deployed), I updated the file with the following powershell:

    $content = Get-Content ".\${assemblyName}.application"
    $content | % { $_.Replace('<expiration maximumAge="0" unit="days" />', '<beforeApplicationStartup />') } | Set-Content ".\${assemblyName}.application"
    

    With this, I finally have all the parameters correct and can sign the deployment manifest and copy everything back.