Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish ClickOnce app with TeamCity

What is the simplest way to have my Visual Studio 2015 solution also publish the ClickOnce app? Is it possible to change ClickOnce settings parameters, e.g. Update URL, when running the build?

like image 819
Dave Avatar asked Aug 26 '15 12:08

Dave


2 Answers

Turns out this is easy:

  • Build step is "MSBuild"
  • Build file points to the Visual Studio solution
  • Set "Target" to "publish"
  • Add "Command Line Parameter": /property:PublishDir="C:\\Users\TeamCity\\Desktop\\publish\\" <= where the ClickOnce artifacts get put

I also had another Command Line Parameter /property:InstallUrl="http://my.domain/app/" so I can set different install locations for different builds (test/production).

I then added a reference to this parameter in my *.csproj file:

<InstallUrl Condition="'$(InstallUrl)' == ''">http://default.domain/app/</InstallUrl>
<InstallUrl Condition="'$(InstallUrl)' != ''">$(InstallUrl)</InstallUrl>

You may also need these in *.csproj to get your ClickOnce app version sync'd with the TeamCity build number:

<ApplicationVersion Condition="'$(build_number)' == ''">1.0.0.2</ApplicationVersion>
<ApplicationVersion Condition="'$(build_number)' != ''">$(build_number)</ApplicationVersion>
<BuildNumber Condition="'$(build_number)' == ''">1.0.0.2</BuildNumber>
<BuildNumber Condition="'$(build_number)' != ''">$(build_number)</BuildNumber>

And set the build number format (Build Configuration > General Settings) to 1.0.0.%build.counter%. Incrementing major/minor for your app manually.

What I then do is create 3 build steps with 3 different versions of the above for development, test and production. So I have the same build of the ClickOnce app that will install and auto-update from my development, test and production websites (I add all 3 builds to the code repository for the site).

I also add the "AssemblyInfo patcher" feature to the TeamCity build configuration and "system.Configuration" Parameter is set to "Release".

like image 174
Dave Avatar answered Sep 27 '22 21:09

Dave


Dave's response above was very helpful (Thanks Dave!). Given this a TeamCity - ClickOnce specific question I figured I add some screenshots (TeamCity v2017.2)

  1. I created two configurations (dev, prod) one is triggered on each commit and the other is manual(prod).

dev and prod

  1. I created a single build step with Targets: of Clean,Build,Publish
  2. Both build configs will use the Configuration Release

Build Step

  1. Where both configuration differ is at the parameters settings. I want dev and prod to publish the ClickOnce files to separate folders which is specified by setting the system.PublishDir
  2. I also wanted dev and prod to be accessible from separate urls which can be done by using the system.InstallUrl
  3. Make sure to terminate your PublishDir and InstallUrl with / otherwise you will get 404 download errors or directory path errors.

Build Parameters 7. Lastly make sure your Configuration WinForms project is set to build (this got me) otherwise TeamCity will not generate the ClickOnce Files.

Release set to build

like image 30
Geovani Martinez Avatar answered Sep 27 '22 19:09

Geovani Martinez