Deployment of Technology
Description
Deployment of Technology document sample
Document Sample


Session 4: Deploying Windows Forms
2.0 Applications with ClickOnce and
Visual Studio 2005
ClickOnce provides a new deployment technology that gives you the best of a rich Windows-
based application user experience, as well as providing the deployment and maintenance
benefits of Web applications. It allows a user to download and execute a rich client application
over the Web, off a network file share, or from local media, hence allowing the application to be
run offline. It offers a full Windows user interface running on a desktop, whilst allowing single
server deployment of application files and updates.
Objectives
The objective of this lab is to trial the new ClickOnce deployment technology for Microsoft®
Windows® Forms applications.
After completing this lab you will be able to:
Publish and deploy a client application using Visual Studio
Update the application
Roll-back that update
Configure the application‟s security settings to run with “Local Intranet” zone permissions
(Advanced)
Update the application using the System.Deployment APIs (Advanced)
Note: The same application will be used for all exercises. Each exercise has the previous exercise as
a pre-requisite. Also, the client application has no user interface other than the default form in a
Windows Forms application. This is intentional, so you can see there is no explicit knowledge of the
deployment mechanism in your application.
Scenario:
You are a developer working for “Alpine Ski House”; you will be working on an application called
“MySkiApp”. You will create it, deploy it, roll it back, and configure its‟ security permissions.
Last Saved: 1/18/2011 11:35:00 AM
Last Printed: 1/18/2011 11:35:00 AM
Contents
Lab Setup .......................................................................................................... 3
Exercise 1: Publish and Deploy an application using Visual Studio ...... 1
Exercise 2: Update the Application ........................................................... 4
Exercise 3: Update the Application ........................................................... 6
Exercise 4: Configure application security settings (Advanced)........... 7
Exercise 5: Perform programmatic updates (Advanced) ..................... 11
Lab Summary.................................................................................................. 15
Lab Setup
From the Session Menu on the login screen, choose the Windows XP.NET session
Enter the username and password you were given (not your UTS username/password)
Your VMware image will start up automatically. If it does not, run the command vmware from a
terminal window
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 1
Exercise 1:
Publish and deploy an application using Visual Studio
In this exercise, you will create and publish a client application
Task 1: Create a client application
1. Navigate to Start | Programs | Microsoft Visual Studio 2005 |
Microsoft Visual Studio 2005
2. Select File | New | Project menu command
3. Create a Microsoft Visual Basic® or Microsoft Visual C#® Windows
Application project
a. Set the Location to “c:\labs\ Lab5_ClickOnce”
b. Set the Name to “MySkiApp”
4. Click OK to create the project
5. Open Form1 in the Windows Forms designer
a. Set Form1‟s Text Property “MySkiApp”
Task 2: Publish the application
1. Maximize Microsoft Visual Studio®
2. Select Project | MySkiApp Properties menu command
3. Select Publish from the MySkiApp Tab
Note: See Figure 1.1 for location of Publish button. It is on the bottom
left [some times hidden in low screen resolutions].
Figure 1.1 ClickOnce Publish Pane in Visual Studio
4. In the Publishing Location, enter http://localhost/MySkiApp
2 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Note: You are publishing the application for on-line and off-line use.
This means the application will be downloaded to the ClickOnce store
and a shortcut to the application will be created in Start | Programs
upon download.
5. Click Options
6. The Publish Options dialog appears (see Figure 1.2)
Figure 1.2 Publish Options Dialog
7. Enter “Alpine Ski House” under Publisher name
8. Enter “MySkiApp” under Product name
9. Enter “http://www.alpineskihouse.com as Support URL
10.Click OK to commit changes and close dialog
11.Select Build | Build MySkiApp menu command to compile and build
the application
12.Select Build | Publish MySkiApp menu command
13.Click Finish to publish the application
Note: Publish might take a minute, especially the first time because it
has to create the virtual directory on the web server, upload the files
to the server, etc. Check VS2005 Status bar until it says Publish
succeeded.
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 3
Task 3: Deploy the application
Note: In Task 2, you published an application to a server. ClickOnce
uses a web-like pull model, where end-users come to the publishing
server to install the application. For this task, put on your end-user hat
and install the application.
1. After our publishing in Task 2, Microsoft Internet Explorer appears,
its URL is http://localhost/MySkiApp/publish.htm
2. Click Install in the http://localhost/MySkiApp/publish.htm
webpage.
3. An “Application Install – Security Warning” dialog appears
4. Click Install in the warning dialog
Note: The warning appears because we are not a trusted publisher on
this machine. For details on avoiding the dialog, refer to “Trusted
Application Deployment” in the Visual Studio Help files.
5. MySkiApp downloads and launches
6. Close MySkiApp
7. Close Internet Explorer
Note: The application is now installed into the ClickOnce store. A
shortcut has also been created from Start | Programs | Alpine Ski
House | MySkiApp, so you can start the app without having to go back
to URL.
4 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Exercise 2:
Update the Application
In this exercise, you will make a change to the MySkiApp application.
You will then publish and deploy this change to update MySkiApp.
Task 1: Make changes to the Application
1. Go back to Visual Studio 2005
2. In Solution Explorer, double-click on Form1
3. Form1 appears in the designer
4. Set the BackColor Property in Form1 to “Desktop”
5. Select Build | Build Solution menu command
Task 2: Make changes to the Application
1. Maximize Visual Studio
2. Select Project | MySkiApp Properties menu command
3. Select Publish from the MySkiApp Tab
Note: See Figure 1.1 for location of Publish button. It is on the bottom
left [some times hidden in low screen resolutions].
4. Click Updates
5. The Application Updates dialog appears (see Figure 1.3)
Figure 1.3 Application Updates options
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 5
Note: ClickOnce has two options for checking for updates:
It can check before the application starts, so you will
always run the latest version; or it can change after the
application starts, so you install the updates the next time
the application is run
If you specify a minimum version, end-users will be
automatically updated to that version (if they are running
an older one) when launching the application. If you don‟t
specify a minimum version, the user will be asked if they
want to install the update.
6. Click OK to accept current settings
7. Select Build | Publish MySkiApp menu command
8. Click Finish
9. The IE window with the URL to our Publish file appears
10. Close the IE window without clicking the Install button
Note: You published the update (but did not install it).
Next time the application is launched, ClickOnce will automatically
detect (via manifest) that the files have changed and prompt the end-
user to install it or skip the update.
Task 3: Update the application
1. Navigate to Start | Programs | Alpine Ski House | MySkiApp
2. An Update Available dialog appears (see Fig 1.4)
Figure 1.4 Update Available dialog.
6. Click OK to download and install the update
7. MySkiApp downloads and launches
8. Notice that the BackColor of MySkiApp has been updated. We are
running the updated version.
9. Close the MySkiApp application.
6 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Exercise 3:
Update the Application
In this exercise, you will roll-back the update deployed in Exercise #2.
You must complete Exercise #2 first.
Task 1: Rollback the application
3. Navigate to Start | Settings | Control Panel | Add or Remove
Programs
4. Locate the MySkiApp entry
5. Click Change/Remove
6. The MySkiApp Maintenance window appears (see Figure 1.5)
Figure 1.5 MySkiApp Maintenance window
7. Click OK to rollback to previous version of the application
8. Click OK in the Application Restored dialog
Task 2: Confirm the rollback
1. Navigate to Start | Programs | Alpine Ski House | MySkiApp
2. Notice the application is back to the grey (Control) color
background. You have successfully rolled back the application
Note: ClickOnce stores applications side-by-side. It keeps the last two
„revisions‟ so you always have one version to rollback to.
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 7
Exercise 4:
Configure Application Security Settings (Advanced)
ClickOnce applications run in a security sandbox – similar to the
ActiveX® sandbox in Internet Explorer.
The current MySkiApp has been running with Full Trust permissions.
In this exercise, you will configure MySkiApp to run in the “Local
Intranet Zone” permissions sandbox and then customize its permissions
so it can write to the file system - a permission not automatically
granted to applications in this zone.
Task 1: Configure MySkiApp to run with “Local Intranet”
permissions
1. Close any open applications except for Visual Studio
2. Go back to Visual Studio
3. Select Project | MySkiApp | Properties menu command
4. Click Security in the Application toolstrip on the left of the
MySkiApp tab (see Figure 1.6)
5. Click “This is a partial trust application” radio button to enable
security zones
Figure 1.6 ClickOnce application Security settings
6. Select “Local Intranet” in the “Zone your application will be
installed from” combobox
7. Click the Calculate Permissions button to make sure MySkiApp has
the permissions needed
8. Review the Permissions required by the application
8 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Note: For each permission, the Setting can be either:
Include – to explicitly include the permission
Zone Default - to be assigned the permission for the zone. This
neither explicitly grants it nor excludes it. You will only get
the permission at deployment if the zone permission group
includes it
Exclude - to explicitly exclude the permission.
The Included column can have either a green button with a checkbox,
a security warning, or nothing. It will have the green button for each
permission that either:
the zone already includes (usually combined with a Setting of
Zone Default)
the application explicitly including (usually combined with a
setting of Included)
It will have a yellow warning icon when the application requires higher
trust than the permissions granted in the target security zone. This
way you know that ClickOnce will elevate your permissions when you
deploy (See Figure 1.6).
Task 2: Debug the application in Local Intranet Zone
1. Click Advanced in the Security pane (at the bottom of the pane)
2. The Advanced Security Settings dialog appears
Figure 1.7 Advanced Security Settings dialog.
Note: When you enabled ClickOnce Security Settings, Visual Studio
changes your debug settings to debug in the target security zone. This
way your application behaves the same when it is debugged and when
it is deployed.
3. Click OK to accept the current settings and agree to be debugged
in the sandbox
4. Select Debug | Start Debugging to run the application
5. MySkiApp launches without problems
6. Close MySkiApp to stop debugging
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 9
Task 3: Add code that needs higher permissions
1. Open Form1 in forms designer
2. Double-click on Form1 to add a Form_Load event handler
3. Add the following code to the Form_Load event handler:
C#:
// Prompt for a file dialog to open
OpenFileDialog openFileDialog = new OpenFileDialog();
// Make sure we are selecting files that exist
openFileDialog.CheckFileExists = true;
// Check if the user clicks OK
if ( openFileDialog.ShowDialog() == DialogResult.OK)
{
using (System.IO.Stream s = openFileDialog.OpenFile())
{
}
}
4. Select Debug | Start Debugging
5. A SecurityException occurs
Note: The security exception occurs because we are debugging with
code that has the Local Intranet Zone sandbox permissions. MySkiApp
will need elevated permissions to run in the Local Intranet zone.
Task 3: Elevate application permissions
1. Select Project | MySkiApp Properties menu command
2. Click Security to go to the security pane
3. Find the FileDialogPermission in the Permissions required by the
application table
4. Change the Setting column from (Zone Default) to Include (See
Figure 1.8)
5. Find the FileIOPermission in the Permissions required by the
application table
6. Change the Setting column from (Zone Default) to Include (See
Figure 1.8)
7. Notice some of the permissions have a yellow warning. The tooltip,
for the permissions with a warning, states that our application will
require elevated permissions (See Figure 1.8)
10 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Figure 1.8 Elevating permissions to include FileDialogPermission
8. Select Debug | Start Debugging
9. Notice that the OpenFileDialog comes up. In our previous debug
attempt we got a SecurityException when trying to open this
dialog. This means our permission elevation was successful.
10.Click Cancel to dismiss the OpenFileDialog
11.Close MySkiApp
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 11
Exercise 5:
Perform programmatic updates (Advanced)
All of the application updates we have published so far were
automatically installed when the application launched. ClickOnce also
offers the flexibility for an application to programmatically check for
updates and download these updates.
Task 1: Add Reference to System.Deployment assembly
1. Go back to Visual Studio
2. Select Project | Add Reference menu command
3. Select “System.Deployment” component
4. Click OK
Note: The ClickOnce APIs are in this System.Deployment assembly. The
assembly is included with .NET framework 2.0.
Task 2: Reset Security Settings
Note: Let‟s roll back the changes we made in the last (Security) task.
1. Open Form1 in the Code Editor
2. Comment out all the code inside Form1_Load
Note: You can comment out the code by highlighting and pressing Ctrl-
K Ctrl-C
3. Select Project | MySkiApp Properties menu command
4. Click Security to show the security pane
5. Click This is a full trust application radio button to reset your
security changes that we changed in the previous exercise.
6. Click the [X] (close icon) in the security pane to close it and go
back to the designer
Task 3: Add code to the application to check for updates
1. Open Form1 in Forms Designer
2. Drag a button from Toolbox to Form1
3. Set the following properties on the button:
a. Text = “Check for Updates”
b. Name = “buttonUpdates””
12 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
4. Double-click buttonUpdates in the designer to add a Click Handler
5. Enter the following code in the buttonCheck_Click function:
C#:
// Check that app was deployed using ClickOnce
if
(System.Deployment.Application.ApplicationDeployment.IsN
etworkDeployed)
{
// Are there updates available ??
if
(System.Deployment.Application.ApplicationDeployment.
CurrentDeployment.CheckForUpdate())
{
if (MessageBox.Show("Do you want to download
it?", "There is an update available",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Code to download update here
bool successfuldownload = true;
if ( successfuldownload)
{
MessageBox.Show("Application has been
updated");
}
else
MessageBox.Show("Update failed");
}
}
}
Note: The code above does not do the update. It just checks for it.
Notice we hard coded the „successfuldownload‟ variable to true. Also,
to check for an update programmatically, you need to execute two
lines of code:
Check that the application IsNetworkDeployed
CheckForUpdate
The rest of the code is User interface glue for the demo. The
deployment API is very simple and compact.
Task 4: Add code to download the updates
1. Replace the initialization for successfuldownload (in
buttonCheck_Click) with code to download the update:
C#:
bool successfuldownload =
System.Deployment.Application.ApplicationDeployment.Curr
entDeployment.Update();
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 13
Task 5: Publish and deploy the app
1. Select Build | Publish MySkiApp menu command
2. Click Finish
3. IE appears with a webpage for
http://localhost/MySkiApp/publish.htm
4. Click Install in the publish.htm webpage
Note: The version of the application we are installing is the version
that includes the code to programmatically check for updates. We
have to install it before we can use it ☺
. Once we have installed it,
we will use the APIs to download subsequent updates.
5. An Application Install – Security Warning appears
6. Click Install to dismiss the warning
7. MySkiApp downloads and launches
8. Close MySkiApp
9. Close Internet Explorer
Task 6: Publish an update to the application
1. Go back to Visual Studio
2. Open Form1 in the designer
3. Set Form1 BackColor to “ButtonHighlight”, so we have an update to
deploy
4. Select Build | Publish MySkiApp menu command
5. Click Finish
6. IE appears with a webpage for http://localhost
/MySkiApp/publish.htm
7. Close IE with out clicking install
14 Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005
Task 6: Download the Installation programmatically
1. Navigate to Start | Programs | Alpine Ski House | MySkiApp
2. An Update Available dialog appears
3. Click Skip because we are going to download the update
programmatically (on-demand)
4. MySkiApp window appears
5. Click Check for Updates
6. A There is an update available messagebox appears (See Figure
1.10)
7. Click OK to dismiss the Add Database Reference dialog box
Figure 1.10 Our application has detected (programmatically)
that an update is available
8. Click Yes to install the update
9. Click OK on the Application has been updated dialog (see Figure
1.11)
Figure 1.11 Our application has successfully installed
an update (programmatically)
10.Close MySkiApp
11.Navigate to Start | Programs | Alpine Ski House | MySkiApp
12.MySkiApp window appears
13.Notice how the application was updated (it has a buttonhighlight
BackColor)
Session 4: Deploying Windows Forms 2.0 Applications with ClickOnce and Visual Studio 2005 15
Lab Summary
In this lab you performed the following exercises:
Publish and deploy a client application using Visual Studio
Update the application
Roll-back the update
Configure the application‟s security settings to run with “Local
Intranet” zone permissions (Advanced)
Update the application using the System.Deployment APIs
(Advanced)
ClickOnce is a new deployment technology that brings the web
deployment model (click and download) to client applications. In this
lab, you used VS2005 to publish an application, install it and update it
without having to write any code. Your application did not have to
know it was going to be deployed via ClickOnce.
There are extra features ClickOnce adds to your deployment, such as
side-by-side installations, shell integration (with a shortcut in Start |
Programs) and integration with Add or Remove Programs.
Visual Studio 2005 makes it very easy to modify your deployment, so it
can have tight control of the permissions it requests and granted
(providing a more secure deployment).
In this lab, you also used ClickOnce APIs to check for programmatic
updates. For lab simplicity, we used the synchronous APIs; ClickOnce
has synchronous and asynchronous APIs for most operations. With two
lines of code, you can check if an update is available and download it,
so it is ready next time application is launched.
Related docs
Other docs by ooe82464
Get documents about "