giammin
giammin

Reputation: 18958

ClickOnce does not copy data file on update

We are experiencing this strange issue with one of our ClickOnce-deployed applications:

On some client machines, ClickOnce when updating the application does not copy the old database in the .pre folder.

ClickOnce updates the application, but it behaves like it is a new installation.

Another strange thing is that despite it is specified a minimum required version to force any client to update the client PCs which have this issue display the ClickOnce upgrade prompt (it also displays the "Restore the application to its previous state" in the control panel "Program and features" item).

Indeed, other client PCs upgrade automatically without prompting and ClickOnce update behaves like it should.

This is a mature application and this is our 30th publication.

Another element is: Usually we published this application alternatively with two PCs but after installing Visual Studio 2012 we cannot use them to publish ClickOnce and then we create a virtual machine only for publishing this application.

--------------UPDATE----------------

I accepted RobinDotNet's solution because it is DAMN RIGHT to not rely on ClickOnce moving your data reliably.

I also found that you cannot rely on ApplicationDeployment.IsFirstRun.

I changed my code to use my internal check for IsFirstRun and now every updates run smoothly.

Upvotes: 1

Views: 1568

Answers (1)

RobinDotNet
RobinDotNet

Reputation: 11877

As you have found, you can not rely on ClickOnce moving your data reliably. I strongly recommend that you put your data in LocalApplicationData, even if it involves moving a database.

I suspect your problem (and that of not being able to use two different VS2012 instances) is because of the certificate that you use to sign your application. Is it a certificate purchased from a CA, or is it a test certificate created with VS2012? If it's a test certificate, then you probably created a new one on each machine, and each time you publish it, ClickOnce thinks you are changing the certificate, which is part of the identity. When the identity changes, it doesn't carry data forward, and thinks it's a new application. With .NET 3.5, they at least made it stop forcing all of your customers to uninstall and reinstall when you changed the certificate.

Your solution to that is to create one certificate and use it on one machine, then copy it to the other machine. Double-click on it to add it to the certificate store on the second machine, and be sure it's part of the project so you pick up the same one. (In the Signing tab, be sure to select the file, don't select it from the Certificate Store on the machine).

Upvotes: 3

Related Questions