ClickOnce Deployment


With ClickOnce deployment there is no need to start a setup program on the client system. All the client system's user has to do is to click a link on a Web page, and the application is automatically installed. After the application is installed, the client can be offline — there's no need for the client to access the server where the application was installed from.

ClickOnce installation can be done from a Website, a UNC share, or a file location (for example, from a CD). With ClickOnce the application is installed on the client system, it is available with Start menu shortcuts, and it can be uninstalled from the Add/Remove Programs dialog.

ClickOnce deployment is described by manifest files. The application manifest describes the application and permissions required by the application. The deployment manifest describes deployment configuration such as update policies.

In the Try It Out sections of the ClickOnce section, you configure ClickOnce deployment for the Simple Editor you created in Chapter 16.

Successfully deploying the assembly across the network requires that the manifest that is used with the installation must have a certificate associated. The certificate shows for the user installing the application the organization that created the installation program. In the following Try It Out, you create a certificate that is associated with the ClickOnce manifests.

Try It Out – Sign the ClickOnce Manifests

image from book
  1. Open the Simple Editor sample from Chapter 16 with Visual Studio. If you didn't create the sample by yourself, copy it from the downloadable files.

  2. Select Properties for the project in the Solution Explorer, and select the Signing tab as shown in Figure 17-1.

    image from book
    Figure 17-1

  3. Check the checkbox Sign the ClickOnce manifests.

  4. Click the button Create Test Certificate to create a test certificate that is associated with the ClickOnce manifests. Enter a password for the certificate as requested. You must remember the password for later settings. Then click the OK button.

  5. With the Signing properties of the project you can see certificate information as shown in Figure 17-2.

    image from book
    Figure 17-2

How It Works

A certificate is used that the user installing the application can identify the creator of the installation package. By reading the certificate, the user can decide if he can trust the installation to approve the security requirements.

With the test certificate you just created, the user doesn't get real trust information and receives a warning that this certificate cannot be trusted, as you will see later. Such a certificate is for testing only. Before you make the application ready for deployment, you have to get a real certificate from a certification authority such as Verisign. If the application is only deployed within the Intranet, you can also get a certificate from a local certificate server if there's one installed with your local network. The Microsoft certificate server can be installed with Windows Server 2003. If you have such a certificate, you can configure it by clicking the button Select from File... with the Signing options.

In the next Try It Out, you configure the permission requirements of the assembly. When the assembly is installed on the client, the required permissions must be approved.

image from book

Try It Out – Define the Permission Requirements

image from book
  1. Select Properties for the project in the Solution Explorer and select Security, as shown in Figure 17-3.

    image from book
    Figure 17-3

  2. Select Enable ClickOnce Security Settings.

  3. Click the radio button This is a partial trust application.

  4. Select the zone (Custom) as special security permissions are required by the application.

  5. Click the Calculate Permissions button to calculate the permissions that are required by the application.

How It Works

Security is an important aspect of .NET applications. .NET uses evidence-based security to define what assemblies are allowed to do.

On one hand resources should be secured. Examples of such resources are files and directories, networking sockets, and environment variables. For all these resources, .NET permissions exist that allow access to them. One example is the FileIOPermission class, which can be used to allow access to the complete file system or to specific files and directories.

On the other hand you must define who is allowed to use these resources. Here, assemblies are grouped into different categories. Examples of such groups are assemblies that are installed locally, and assemblies that are loaded from the network. You can also define a category of assemblies from a specific manufacturer.

Note

You can read the book Professional C# 2005 (Wiley Publishing, Inc.) for more information about evidence-based security.

The Calculate Permissions button from the Security properties of Visual Studio analyzes the code used by the application to check the application's permission requirements. The result of this analysis is an application manifest that includes all required permissions. With Visual Studio 2005, you can see the application manifest with the name app.manifest below Properties in the Solution Explorer. The content of this file is shown here. The XML element <applicationRequestMinimum> defines all required permissions of the application. the FileIOPermission is required because the application reads and writes files using classes from the System.IO namespace.

<?xml version="1.0" encoding="utf-8"?> <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft- com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">     <security>       <applicationRequestMinimum>         <defaultAssemblyRequest permissionSetReference="Custom" />         <PermissionSet  version="1"             SameSite="site">           <IPermission  version="1" Unrestricted="true" />           <IPermission  version="1" Flags="MemberAccess" />           <IPermission  version="1"              Flags="Execution, ControlEvidence" />           <IPermission  version="1" Unrestricted="true" />         </PermissionSet>       </applicationRequestMinimum>     </security>   </trustInfo> </asmv1:assembly>

By selecting a different zone in the Security dialog, you can verify if the application needs permissions that are not available within the zone.

With the defined security requirements, you can start to publish the application by creating a deployment manifest. This can easily be done with the Publish Wizard, as you see in the following Try It Out.

image from book

Try It Out – Using the Publish Wizard

image from book
  1. Start the Publish Wizard by selecting the menu Build Publish Simple Editor. Enter a path to the Website http://localhost/SimpleEditor, as shown in Figure 17-4. Click the Next button.

    image from book
    Figure 17-4

  2. At step 2 in the Publish Wizard select the option Yes, this application will be available online or offline, as shown in Figure 17-5. Click the Next button.

    image from book
    Figure 17-5

  3. The last dialog gives summary information as you are Ready to Publish! (see Figure 17-6). Click the Finish button.

    image from book
    Figure 17-6

How It Works

The Publish Wizard creates a Website on the local Internet Information Services Web server. The assemblies of the application (executables and libraries) as well as the application and deployment manifests, a setup.exe, and a sample Web page, publish.htm, are copied to the Web server. The deployment manifest describes installation information as shown here. With Visual Studio, you can open the deployment manifest by opening the file SimpleEditor.application in the Solution Explorer. With this manifest you can see a dependency to the application manifest with the XML element <dependentAssembly>.

<assemblyIdentity name="SimpleEditor.application" version="1.0.0.12" publicKeyToken="74fe8381193333a9" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />   <description asmv2:publisher="Thinktecture" asmv2:product="SimpleEditor"        xmlns="urn:schemas-microsoft-com:asm.v1" />   <deployment install="true">     <subscription>       <update>         <beforeApplicationStartup />       </update>     </subscription>     <deploymentProvider          codebase="http://cnagel/SimpleEditor/SimpleEditor.application" />   </deployment>   <dependency> <dependentAssembly dependencyType="install" allowDelayedBinding="true"  codebase="SimpleEditor_1_0_0_1\SimpleEditor.exe.manifest"  size="6789"> <assemblyIdentity name="SimpleEditor.exe" version="1.0.0.1"  publicKeyToken="74fe8381193333a9" language="neutral"  processorArchitecture="msil" type="win32" /> <hash> <dsig:Transforms> <dsig:Transform Algorithm= "urn:schemas-microsoft-com:HashTransforms.Identity" /> </dsig:Transforms> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <dsig:DigestValue>fL/kgd9/L3dmbuIfkSrU8AU1mbg=</dsig:DigestValue> </hash> </dependentAssembly> </dependency>

By selecting the option as shown in Figure 17-5, you've specified that the application will be available online and offline. This way the application is installed on the client system and can be accessed from the Start menu. You can also use Add/Remove Programs to uninstall the application. If you select that the application to be available only online, the user must always click the Website link to load the application from the server and start it locally.

The files that belong to the application are defined by the project output. You can see the application files with the Properties of the application in the Publish settings by clicking the button Application Files..., as shown in Figure 17-7.

image from book
Figure 17-7

The prerequisites of the application are defined with the Prerequisites dialog (see Figure 17-8) that can be accessed by clicking the Prerequisites button. With .NET 2.0 applications, the prerequisite .NET Framework 2.0 is automatically detected, as the figure shows. You can select other prerequisites with this dialog.

image from book
Figure 17-8

Now, you can install the application by following the steps in the next Try It Out.

image from book

Try It Out – Installation of the Application

image from book
  1. Open the Web page publish.htm, as shown in Figure 17-9.

    image from book
    Figure 17-9

  2. Click the Install button to install the application. Next, a security warning will pop up (see Figure 17-10).

    image from book
    Figure 17-10

  3. Click the More Information link to see the potential security issues with the application. Read the categories of this dialog, shown in Figure 17-11.

    image from book
    Figure 17-11

  4. After reading the dialog information, click the OK button and press the Install button of the Application Install dialog.

How It Works

When the file publish.htm is opened, the target application is checked for version 2.0 of the .NET runtime. This check is done by a JavaScript function inside the HTML page. If the runtime is not installed, the runtime is installed together with the client application. With the default publish settings the runtime is copied to the Web server.

By clicking the link to install the application, the deployment manifest is opened to install the application. Next, the user is informed about some possible security issues of the application. If the user clicks OK, the application is installed.

image from book

Updates

With the default publish, the client application automatically checks the Web server for a new version. In the following Try It Out, you try such a scenario with the Simple Editor application.

Try It Out – Updating the Application

image from book
  1. Make a change to the Simple Editor application that shows up immediately, like setting the background color of the text box.

  2. Build the application and start the Publish Wizard once more using the same settings as before.

  3. Do not click the link on the Web page publish.htm; instead, start the client application from the Start menu. When the application is started, the dialog shown in Figure 17-12 pops up asking if a new version should be downloaded. Click the OK button to download the new version. When the new version launches, you can see the application with the colored text box.

    image from book
    Figure 17-12

How It Works

The update policy is defined by a setting in the deployment manifest with the XML element <update>. You can change the update policy by clicking the Updates... button with the Publish settings. Remember to access the Publish settings with the properties of the project. The Application Updates dialog is shown in Figure 17-13.

image from book
Figure 17-13

With this dialog, you can define whether the client should look for updates at all. If updates should be checked, you can define whether the check should happen before the application starts or if the update should occur in the background while the application is running. If the update should occur in the background, you can set the time interval for them: with every start of the application, or with a specific number of hours, days, or weeks.

image from book




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net