May 22, 2008

ClickOnce Deployment

I recently made the first pre-release of my latest .NET 3.5 application for my customer. This application is for an occasionally disconnected database and leverages the new Microsoft Sync framework via SQL Server Compact Edition (SSCE) 3.5. The reason I wanted to use a ClickOnce deployment is because it will automatically install both .NET 3.5 and the SSCE software directly from the Microsoft site if the target machine requires it. While the process wasn't too onerous, it did take multiple attempts to achieve a working distribution.
The first step is to right-click on your project in the Solution Explorer and select Properties. When the properties page appears use the tabs on the left hand side and select Publish. The first thing to fill in is the Publish location. I just picked a convenient folder near the root of my solution. Since I am just emailing the files to the customer, I picked the install radio button for offline. I also told it to automatically increment the revision number.

The second step is to configure the files for your deployment, click the Application Files... button. For the first pass I tried the default settings but that did not work. The Prerequisite (Auto) setting is fine for files that will be in the target machine's GAC (typically the .NET framework stuff only). I had some .dlls that are in my GAC, that I don't copy to the output directory so I had to change the dropdown list to Include for those files.
The SSCE .sdf file has to be set to Data File (auto), or it won't end up in the correct place. Before I did this I was curious as to which .sdf file would get copied, the one in my project or the one in my output /bin folder. It turns out to to be the latter, which worked fine for a pre-release but in the final release I will have to either set the .sdf file's Copy to Output Directory property to Always Copy or at least remember to move it manually so that the user starts off with a virgin copy of the local data store.
The third step is to check the publish options. I just entered the publisher name and product name fields here. I turned off the checkbox for Use ".deploy" file extension but I probably could have left it alone. I wasn't sure what to do about the security settings for the application but since I was worried about it now working without the proper security I decided to sign the application and I left the Use application manifest for trust information selected.

The fourth step was to just check the Prerequisite settings. This is where you can specify other supporting tools to download automatically. Visual Studio 2008 automatically figured out what I needed and everything was checked so I only had to click the OK button.

I'm not using the automatic update features of the ClickOnce deployment yet so under the Updates... button I just made sure the checkbox This application should check for updates was clear.
The penultimate step was to sign the application using the Signing tab of the properties page. I ended up doing this several times. The final time I just created a new certificate, named it after the app, entered a password for it and created it. This process crated a .pfx file in the solution explorer. The initial deployment produced a perplexing error message about the manifest having a different computed hash and the .sdf file. The solution appeared to be setting the Copy to Output Directory property to Always Copy for this newly created .pfx file.

The final step was to click the Publish button, wait a few minutes and then zip the resulting folder and send it to the customer.


Jeff said...

I've been running into a problem where I need to use the application manifest for trust information but would like to specify "Branding Information" in the deployment assembly without re-signing the deployment with a valid code-signing cert.

Any ideas on a workaround?

Travich said...

I wonder why my SDF file does not show up in my click once for application files. Is it because it's in a different project that I'm referencing?

Travich said...

I wonder why my SDF file does not show up in my click once for application files. Is it because it's in a different project that I'm referencing?

Tod said...

I just discovered today a way to make sure files get deployed. See my latest blog entry on click once and see if that helps.

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.