Using the Publish Wizard

1. Create an Excel Workbook project with VSTO.

2. Add the code in Listing 11.1 to the ThisWorkbook_Startup method. This action creates an empty actions pane with a blue background. The background color makes it easy for you to see that your code is running.

Listing 11.1. Creating an empty actions pane with a blue background

ActionsPane.BackColor = Color.Blue ActionsPane.Visible = True

3. Set the publish version.

You control the publish version of the application from the Publish tab of the project Properties page. Double-click the My Project node in Solution Explorer, and select the Publish tab to view the Publish Wizard properties, as shown in Figure 11.11. The publish version number is different from the file or assembly version number, which is the version of an individual file within your application. The publish version is the overall version of your solution; it is the one number that represents all the individual files, each of which may have a different version number. The publish version is a four-dot number: Major.Minor.Revision.Build. By default, VSTO sets the Publish Wizard to automatically increment the build part of the version number starting at So the second time you publish, the publish version number will be, and then, and so on.

Figure 11.11. Setting the Publish Location and Publish Version

4. Set the default Publish Location.

You can instead change this in the Publish Wizard, but it is a good idea to set it here so that each time you run the wizard the correct value will be set. This path can be either an HTTP URL to which you have permission, or a local file or universal naming convention (UNC) path, as shown in Figure 11.12.

5. Publish the solution with the Publish Wizard.

You can launch the Publish Wizard in a number of ways. One way is to click the Publish Now button on the Publish tab. This action publishes the solution using the settings from the Publish tab and does not display the Publish Wizard. Or you can run the Publish Wizard by clicking Publish ExcelWorkbook1 from the Build menu. You can also launch the Publish Wizard by right-clicking the project in Solution Explorer and choosing Publish from the Project context menu.

The Publish Wizard opens, and you can set the Publish Location. In this case, you've already set it in the Publish tab, so you do not need to make any changes.

Figure 11.12. First step in Publish Wizard

6. Click Next.

7. Click Finish to confirm the publish location and publish the project, as shown in Figure 11.13.

When you click Finish on the Publish Wizard, the wizard closes and the confirmation that it completed successfully is shown in the status bar.

Figure 11.13. Final step in Publish Wizard

You can also see the Publish Wizard details in the Output window. To open the Output window, navigate to the Debug menu, point to Windows, and then click Output. The Output window will open. In the Show Output From drop-down, select Build to see the build output details. You can see from the details that the project was built and then published.

The Output window is one of the few ways to debug problems using the Publish Wizard. For example, if you cannot find or connect to the publish location, you see an error in the Output window. Figure 11.14 shows the successful publishing of an application.

The Publish Wizard has succeeded, and now let's verify that everything is correct and confirm what was published. The first step is to verify the published location. In this case, you published to http://localhost/ ExcelWorkbook1. This location might translate into, for example, C:\Inetpub\wwwroot\ExcelWorkbook1. This is the virtual folder of your publish Web site on your machine.

Show output from: Build

Project: Exceltforkbookl,

Connecting to 'http: ^localhost/ExcelWorkbookl/ ■... Publishing files...

Verifying ExcelWorkbookl.application... <1 of €) Verifying ExcelHorkbookl.xls... <2 of 6) Verifying ExcelWorkbookl.application.,, <3 of €) Verifying ExcelWorkbookl.dll... <4 of 6)

Verifying ExcelWorkbookl.<111.manifest___ (S of 6)

Verifying ExcelHorkbookl.xls... (6 of 6) Publish success.

Publish: 1 succeeded, 0 failed, 0 skipped

Configuration: Release Any CPU

0 skipped

[s] Output f^Error List | (^Immediate Window

Figure 11.14. A published application in the Output window

You can see that the Publish Wizard has created a directory that contains your application. This folder is the name of the project followed by an underscore and the version number—for example, ExcelWorkbook1_1.0.0.0. Two files are published at the root: the Excel document and the deployment manifest. The deployment manifest ends with the .application extension. This is an unfortunate extension, and the file is even misi-dentified by Windows Explorer as the application manifest, as shown in Figure 11.15.

The Excel document, ExcelWorkbook1.xls, has an embedded application manifest that points to the deployment manifest in this directory. The deployment manifest, ExcelWorkbook1.application, points to the current version of the application manifest. In our case we have only one version, so it points to the application manifest, ExcelWorkbook1.dll.manifest, in the ExcelWorkbook1_1.0.0.0 directory. As shown in Figure 11.16, the published application directory contains a copy of the Excel document and the assembly. There are also two manifest files here. The application manifest ends with the .manifest extension and is the same file as the manifest that is embedded in the Excel document. There is also a copy of the deployment manifest, a convenience to administrators to enable easy rollback.

ftr C:\Inetpub\wwwroot\ExcelWorkbookl

-|D| x|

File Edit View Favorites Tools Help

Q Back - Q - Search

* Folders


Address C^netpubV'wwroot^xcelWorkbookl



[0 Desktop El G My Documents El My Computer E ^ D1P10S (C:) Ô Config.Msi E Documents and Settings E Ô Inetpub —

Ir^i AdminScripts IrTi catalog.wci E iissamples E mailroot IrTi Scripts E wwwroot

E Ô aspnet_dient

Q ExcelWorkbookl_l. 0.0.0 T


ExcelWorkbookl. application ■ Application Manifest 2KB

I ExcelWorkbookl.xls

Microsoft Excel Worksheet I 25 KB

J Jj

I J My Computer

3 objects (Disk free space: 7.91 GB)

Figure 11.15. Deployment manifest (not application manifest)

C:\In etpu b\wwwroot\ExcelWorkbookl \ExcelWorkbookl_l .0.0.0


1 File Edit View Favorites Tools Help

Qsack Q - JF




Address C:\Inetpub\wwwroot^xcelWorkbookl^xcelWo

rkbookl_l.0.0.0 Go



Qgr Desktop E Q My Documents B My Computer E ^ D1P10S (C:) Ir^i Config.Msi E Documents and Settings E Ô Inetpub

IrTi AdminScripts Ir^i catalog.wci E iissamples E mailroot IrTi Scripts E wwwroot

ExcelWorkbookl. application ■ Application Manifest 2KB



ExcelWorkbookl.dll. manifest



Date Modified: 6/25/2006 12:16 PM

159.5 KB I J My Computer

4 objects (Disk free space: 7.91GB)

Figure 11.16. Application manifest

For the solution to run, you must set the CASPOL. The Publish Wizard does not check that the client machine is set up correctly, and it does not set the security policy to allow your solution to run. You should assume for this example that your machine is set up correctly. You will use the .NET 2.0 Configuration tool to give your solution full trust permissions based on the published location.

1. Open the .NET 2.0 Configuration tool.

2. In the Control Panel, select Performance and Maintenance, and then select Administrative Tools.

3. In the Administrative Tools window, open the Microsoft .NET Framework 2.0 Configuration tool, as shown in Figure 11.17.

if« .NET Framework Z.0 Configuration


File Action View Help o | 15 HE Jt Eja m I X Iff f ~l Console Root

B ^ .NET Framework2.0 Configuration B"{M My Computer

^ Assembly Cache ■ig Configured Assemblies J55] Remoting Services B-Qj) Runtime Security Policy Enterprise B Machine

Intranet_Same_Site_Access Intranet_Same_Directory_Access B^ Internet_Zone

^ Restricted_Zone B ^ Trusted Zone bJ Pe'nission Sfts Qj) Po icy Assemblies B £ User Applications

LocalIntranGt_ZoriG Code Group


Code group grants the intranet permission set to code from the intranet zone. This permission set grants intranet code the right to use isolated storage, full UI access, some capability to do reflection, and limited access to environment variables.

Assembly evidence must match this membership condition to belong to the code group: Zone: Intranet.

Assemblies matching the membership condition are granted this permission set at the current policy level: Locallntranet.

Permission Set Description:

Default rights given to applications on the local intranet

Figure 11.17. The Configuration tool

4. Create a new security code group to define your solution, and specify the permissions it is granted. In the .NET Framework 2.0 Configuration tool, expand the tree My Computer | Runtime Security Policy | Machine | Code Groups | All_Code | LocalIntranet_Zone.

5. Right-click LocalIntranet_Zone, and click New. This action opens the Create Code Group Wizard, as shown in Figure 11.18.


Identify the new Code Group

The new code group should have a name and description to help others understand

its use.


Create a new code group




Your VSTO Solution for Excel


mport a code group from a XML File

Browse... j

Next > Cancel

Figure 11.18. Create Code Group Wizard

Figure 11.18. Create Code Group Wizard

6. Type a name for your code group, and add an optional description.

7. Select Next to continue.

8. In the second step in the Create Code Group Wizard, define the evidence that allows code to belong to this group, as shown in Figure 11.19. Choose URL as the condition type, and type the URL of your solution as the published path. By adding the asterisk (*) to the end of the path, you allow all code under this path to belong to the group. Keep this group as small as possible, and make sure that only trusted users have rights to add code to this directory.

9. Click Next.

10. Define the permissions used by the code belonging to this group, as shown in Figure 11.20. All VSTO solutions require full trust, which is the default.

Figure 11.19. Setting membership conditions
Figure 11.20. Assigning a permission set

11. The final step in the Create Code Group Wizard is a confirmation screen, as shown in Figure 11.21. Click Finish to create the new code group.

Figure 11.21. Final step of Create Code Group Wizard

Figure 11.22 shows your newly created code group. If you click the name of the code group, you will see its details in the right pane. Note that there is a known issue with the tool that adds "Copy of" to the name of your code group. To keep your CASPOL organized, you should rename it to the correct name. You can also see the details of the code group in the right pane when you select a node.

Now it's time to run the solution. Using Internet Explorer, browse to the http://MyWebServer/ExcelWorkbook1/ExcelWorkbook1.xls file. The result is that your VSTO Excel document opens and your code runs. You can also copy this document to your local machine and run it from there. When you open the document, the VSTO loader finds the assembly in the published location and runs it.

ifët .NET Framework 2.0 Configuration


File Action Vjew Help ts ¡0 a ^ e I x.if f~'~l Console Root

B ^ .NET Framework 2.0 Configuration □■■fâ My Computer

^ Assembly Cache L(s} Configured Assemblies i^j Remoting Services H Qj) Runtime Security Policy EE-^j Enterprise È ^ Machine

□ L^ Code Croups 3 & AII_CoJe i+1 ^ My_Conpjter_Zone bJ ^ I oral nfTanet_/one

Intaret_Sa"ne_Site_Access Intranet_Same_Directory_Access

Copy of ExcelWorkbookl

B ^ Internet Zor e

^ Kestrictec_Zone 0 Trusted_Zone □ Qjl Pe'mssion Sets Po icy Assemblies 0 C User ■■(p^ Applications

Copy of ExcelWorkbookl Code Group


Assembly evidence must match this membership condition to belong to the code group: Uirl: http ://My PC/Excel Workbookl/*.

Assemblies matching the membership condition are granted this permission set at the current policy level: FullTrust.

Permission Set Description: Allows full access to all resources


Edit Code Group Properties The Code Group Properties dialog box allows you to edit this code group's name, description, membership condition, and permission set.

Figure 11.22. Code group details

0 0

Post a comment