click the Start node and select Add Dialog from the context menu. Highlight the dialog titled
Checkboxes (A) from the Add Dialog window and click OK. This inserts the new dialog at the end
of the installation process. The order of the dialogs can be adjusted using the Move Up/Down items
from the right-click context menu on the nodes in the User Interface window.
Selecting Properties Window from the right-click context menu on the new dialog brings up the
Properties window. Set the property identifier for Checkbox1 to STARTAFTERINSTALL and then set
the Visible property for the remaining checkboxes to false. As discussed earlier in the chapter,
976 .
chaPter 48 pAckAging And deploymenT
you also needed to add /STARTAFTERINSTALL=[STARTAFTERINSTALL] to the CustomActionData
property for the assembly in the Custom Actions view of the deployment project. With this user
input you can decide whether to start the service when the installer completes.
clickonce
Using a Windows installer is a sensible approach for any application development. However, deploying
an installer to thousands of machines, and then potentially having to update them, is a daunting task.
Although management products help reduce the burden associated with application deployment,
web applications often replace rich Windows applications because they can be dynamically updated,
affecting all users of the system. ClickOnce, introduced in version 2.0 of the .NET Framework, enables
you to build self-updating Windows applications. This section shows you how to use Visual Studio
2010 to build applications that can be deployed and updated using ClickOnce.
one click to deploy
To demonstrate the functionality of ClickOnce deployment, this section uses the same application
used to build the Windows Installer, CallCentre, which simply displays an empty form. To deploy
this application using ClickOnce, select the Publish option from the right-click context menu of
the project. This opens the Publish Wizard, which guides you through the initial configuration
of ClickOnce for your project.
The first step in the Publish Wizard allows you to select a location to deploy to. You can choose to
deploy to a local web site, an FTP location, a file share, or even a local folder on your machine. Clicking
Browse opens the Open Web Site dialog, which assists you in specifying the publishing location.
The next step asks you to specify where the users are expecting to install the application from. The
default option is for users to install from a CD or DVD-ROM disc. More commonly, you will want
to install from a file share on a corporate intranet or a web site on the Internet. Note that the
location you publish to and the location the users install from can be different. This can very useful
while testing new releases.
The contents of the final step will change depending on the installation option selected. If your
application will be installed from a CD or DVD-ROM, this step asks if the application should
automatically check for updates. If this option is enabled you must provide a location for
the application to check. In the case that your users will be installing from a file share or web site,
it is assumed that the application will update from the location that it was originally installed from.
Instead, the final question relates to whether or not the application will be available offline. If the
offline option is selected, an application shortcut is added to the Start menu and the application can
be removed in the Add/Remove programs dialog in the operating system. The user will be able to
run the application even if the original installation location is no longer available. If the application
is only available online, no shortcut is created and the users have to visit the install location every
time they want to run the application.
The last screen in the wizard allows you to verify the configuration before publishing the application.
After the application has been published, you can run the Setup.exe bootstrap file that is produced
to install the application. If you are installing from a web site, you will get a default.htm file
Clickonce .
977
generated as well. This file, shown in Figure 48-17, uses some JavaScript to detect a few dependencies
and provides an Install button that launches the Setup.exe.
fiGure 48-17
Clicking the Install button at this location displays a dialog prompting you to run or save
Setup.exe. Selecting Run (or running Setup.exe from a different kind of install) shows the
Launching Application dialog, shown in Figure 48-18, while components of your application
are being retrieved from the installation location.
After information about the application has been downloaded, a security warning is launched, as
shown in Figure 48-19. In this case, the security warning is raised because, although the deployment
manifest has been signed, it has been signed with a certificate that is not known on the machine on
which it is being installed.
fiGure 48-18 fiGure 48-19
978 .
chaPter 48 pAckAging And deploymenT
The deployment manifest of a ClickOnce application is an XML file that
describes the application to be deployed along with a reference to the current
version. Although it is not required, each deployment manifest can be signed
by the publisher to provide the manifest with a strong name. This prevents the
manifest from being tampered with after it is deployed.
Three options are available when it comes to signing the deployment manifest. By default,
Visual Studio 2010 creates a test certificate to sign the manifest, which has the format
application name_TemporaryKey.pfx and is automatically added to the solution (this happens
when the application is first published using the Publish Now button). Though this certificate can
be used during development, it is not recommended for deployment. The other alternatives are to
purchase a third-party certificate, from a company such as VeriSign, or to use the certificate server
within Windows Server to create an internal certificate.
The advantage of getting a certifi cate from a well - known certifi cate authority is that it can
automatically be verifi ed by any machine. Using either the test certifi cate or an internal certifi cate
requires installation of that certifi cate in the appropriate certifi cate store. Figure 48 - 20 shows the
Signing tab of the Project Properties window, where you can see that the ClickOnce manifest is being
signed with a certifi cate that has been generated on the local computer. An existing certifi cate can be
used by selecting it from the store or from a fi le. Alternatively, another test certifi cate can be created.
fiGure 48-20
If you want your application to install with a known publisher, you need to add the test certificate
into the root certificate store on the machine on which you’re installing the product. Because this
also happens to be the deployment machine, you can do this by clicking More Details. This opens a
Clickonce .
979
dialog that outlines the certificate details, including the fact that it can’t be authenticated. (If you
are using the certificate created by default by Visual Studio 2010, you will need to use the Select
from File button to re-select the generated certificate, and then use the More Details button.
There seems to be an issue here, in that the details window does not show the Install Certificate
button without this additional step.) Clicking
Install Certificate enables you to specify that
the certificate should be installed into the
Trusted Root Certification Authorities store.
This is not the default certificate store, so you
need to browse for it. Because this is a test
certificate, you can ignore the warning that is
given, but remember that you should
not use this certificate in production. Now
when you publish your application and try
to install it, you will see that the dialog has
changed, looking similar to the one shown in
Figure 48-21.
Although you have a known publisher, you
are still being warned that additional security
permissions need to be granted to this
application in order for it to execute. Clicking
the rather minimalist More Information
hyperlink opens a more informative dialog,
shown in Figure 48-22. As with the security
coding within Windows Server 2008 and
Windows 7, there are three icons: green for
positive security, red for potential security
weaknesses, and yellow for informative or
best practice guidance.
ClickOnce deployment manifests are rated
on four security dimensions. You’ve just seen
how you can specify a well-known publisher,
critical for safe installation of an application. By default, ClickOnce publishes applications as
full trust applications, giving them maximum control over the local computer. This is unusual,
because in most other cases Microsoft has adopted a security-first approach. To run with full trust,
the application requires additional security permissions, which might be exploited. The Sample
Application will be available online and offline; and though this isn’t a major security risk, it does
modify the local file system. Lastly, the location from which the application is being installed is
almost as important as the publisher in determining how dangerous the application might be. In this
case, the application was published within the local network so it is unlikely to be a security threat.
Because this application doesn’t really do anything, you can decrease the trust level that the
application requires. As shown in Figure 48-23, this application is made a partial trust application
based on the Local Intranet zone. This changes the Machine Access icon to green, leaving only the
Installation icon yellow. Unfortunately, the only way you can get this to be green would be to not
install the application, which means that it would not be available offline.
fiGure 48-21
fiGure 48-22
980 .
chaPter 48 pAckAging And deploymenT
fiGure 48-23
Ideally, you would like to be able to bypass the Application Install dialog and have the application
automatically be granted appropriate permissions. You can do this by adding the certificate to the
Trusted Publishers store. Even for well-known certificate authorities, in order for the application to
install automatically, the certificate needs to be added to this store. With this completed, you will
only see the progress dialog as the application is downloaded, rather than the security prompt in
Figure 48-21.
Once installed, the application can be launched either by returning to the installation URL
(Figure 48-17) or by selecting the shortcut from the newly created Start Menu folder with the same
name as the application.
one click to update
At some point in the future you might make a change to your application — for example, you might
add a button to the simple form you created previously. ClickOnce supports a powerful update
process that enables you to publish the new version of your application in the same way you did
previously, and existing versions can be upgraded the next time they are online. As long as you are
content with the current set of options, the update process is just the Publish process. When using
the Publish Wizard to update an existing application, all of the values previously used to publish the
application are preconfigured for you.
You can check the settings in the Publish tab of the Project Properties designer (Figure 48-24).
The designer shows the publish location, the installation location, and the install mode of the
application. There is also a setting for the Publish Version. This value is not shown in the Publish
Wizard, but by default this version starts at 1.0.0.0 and increments the right-most number every time
the application is published.
Clickonce .
981
fiGure 48-24
Along the right are a number of buttons that bring up more advanced options, most of which are
not exposed by the wizard. The Application Updates dialog (Figure 48-25) allows you to configure
how the application updates itself. In Figure 48-25, the application will update once a month after it
has started. You can also specify a minimum required version, which will prevent older clients from
executing until they are updated.
With this change, now when you publish a new version of your application, any existing users will
be prompted to update their application to the most recent version, as shown in Figure 48-26.
fiGure 48-25 fiGure 48-26
982 .
chaPter 48 pAckAging And deploymenT
One of the most powerful features of ClickOnce deployment is that it tracks a previous version of
the application that was installed. This means that at any stage, not only can it do a clean uninstall,
but it can also roll back to the earlier version. The application can be rolled back or uninstalled
from the Programs and Features list from the Control Panel.
Note that for users to receive an update they do need to be able to contact the
original deployment URL when the application performs the check for a new
version (in this case when the application starts). You can also force all users to
upgrade to a particular version (that is, they won’t get prompted) by specifying
the minimum required version in the Application Updates dialog (Figure 49-25).
suMMary
This chapter walked you through the details of building installers for various types of applications.
Building a good-quality installer can make a significant difference in how professional your
application appears. ClickOnce also offers an important alternative for those who want to deploy
their application to a large audience, and with the changes introduced with version 3.5 of the .NET
Framework, it can now be used for a much wider range of applications.
49
Web application Deployment
what’s in this chaPter?
.
Publishing Web Site and Web Application projects
.
Publishing database scripts with Web Applications
.
Copying Web Site changes to a remote server
.
Creating Web Application packages for deployment with the Web