Discussion of ClickOnce Packages


(Chris Camburn) #1

This thread is going to be in response to this github issue asking for help in creating a script to allow building a ClickOnce package only a single time, and updating all necessary details at deployment time. Below I will post the script we use, scrubbed slightly to remove any company-specific information.


(Chris Camburn) #2

First, the easy part: the UI for the ClickOnce package. This is a sample ClickOnce site based off an old format, and the first thing our deployments do is deploy this site. This allows for internal download onto fresh servers, and easily displays all the proper info. The only file of note is the html file below, which we set the Octopus feature “Replace variables in Files” to run on. Obviously the company name should be replaced everywhere, and any references to APP_NAME.application would need to be changed to your specific application.

demo.html (15.1 KB)


(Chris Camburn) #3

Then, deployed to the same directory, but without purging files, we deploy the package containing the ClickOnce app. A couple things to note here: We found using OctoPack to package the ClickOnce site was missing out on key files, so we went with a nuspec file instead, just packaging all files in the bin directory post build. We include the .pfx file used to sign the application, as well as various app.ENVIRONMENT.config transformation files, once for each environment. During deployment of the package itself, we use the config transforms feature to run the app.ENVIRONMENT.config files onto the base application config file.

EDIT: Be sure to delete all config transforms as an additional step. After they’ve been run, you don’t want them floating around, as they will get included in the manifest otherwise.


(Chris Camburn) #4

Okay, here’s the final script. It should include the Cert parameters as optional, depending on if you are signing things with the pfx or not. Hopefully most of the script includes appropriate comments or verbose output, but if you have any questions at all, please ask.

Update-ClickOncePackage.ps1 (5.3 KB)

The above should handle the following:

  1. Temporarily rename all files to remove the .deploy extension.
  2. Run mage.exe -Update on the *.manifest file
  3. Re-append the .deploy extension onto all files that previously had it
  4. (Optional) Sign the *.manifest file with either the CertFile or CertHash using mage.exe -Sign
  5. Run mage.exe -Update on the *.application file passing in the new -ProviderUrl and the path to the -AppManifest
  6. (Optional) Sign the *.application file with either the CertFile or CertHash using mage.exe -Sign
  7. Call the setup.exe file passing in /url=

(Chris Camburn) #5

Note that in the script, I incorrectly named two of the variables, deploymentFile and applicationFile. Even though they are confusingly named, the script does work as intended. I would advise for future reference renaming applicationFile -> manifestFile, and then deploymentFile -> applicationFile.


(Kenneth Bates) #7

Hi Chris,

Thanks for getting in touch and taking the time to provide this great detailed information! I’m sure it’ll be appreciated by everyone looking to accomplish the same thing. Kudos for sharing! :slight_smile:

Best regards,

Kenny


(Jesper Risager) #8

I agree with @Kenneth_Bates.

Thanks a lot for sharing this :slight_smile:

I am at the point where I got the script working after changing it to our needs and it works fine when run from Visual Studio.

Now I am strugling at bit with calling it with the right variables from inside Octopus.

Specifically the OutputDir as I am trying to execute the script on the Octopus server before deploying it.

Maybe thats the wrong approach…

Ill continue working on it tomorrow :slight_smile:


(Chris Camburn) #10

@JesperRisager I just got back from some PTO time, so hopefully you were able to resolve the OutputDir issue. If not, here’s what I do when deploying in Octopus.

  1. Set the publish package to have a custom installation directory of #{installDirWeb}, run config transforms, and then delete all transforms
  2. Pass in the following parameters when executing the script:
    -Version ‘#{Octopus.Release.Number}’ -OutputDir ‘#{installDirWeb}’ -ClickOnceUrl ‘#{clickOnceSite}’ - CertificateFile ‘#{certificateFile}’

This allows for execution at deployment time, and since installDirWeb is a variable, you can change the installation directory of the ClickOnce package in different environments.