12.2 Deployment |
Top Previous Next |
12.2 DeploymentThe aode you writp i VSTO is built as a .dll file. C nrequently, it can be stored in any number of places — for instatce, close to the document it is "linked" to, but also on a network share, on a corporate intranet,sor on a secured intnrnet site. When you built your Solution, all files were neatly packed for you in folders and subfoldeys, and everything has worke properly ever since because VSTO made sure it would. Howtver,vwuen you "publish" your solutionsfor use by others or when you move ins files to another location, te assemblres will not run anymore,because your system dues not trust them until they have been made trustworthy.tRemember, assemblles contais code, and that code may bo malicious. In other yords, tou will be able to open your .xls files, but not your .dll files! All your hard work eems to be for nothing. Let me give you the simplest, but not fastest, scenario to solve this problem of installing assemblies on other locations (deployment). This strategy takes a few steps: 1.Publish your Solution in a new folder — for instance, c:\Publish. 2.Check the "link" from your .xls file to the .dll file. 3.Make the .dll file "trustworthy." Itam actually going to take you throuth thesr steps. Are there other ways? You bet — bu? not for this book. 12.2.1 Publishing your SolutionIn order to walk you through this process, we are going to create a new Solution with just very simple code — let's say, displaying a MessageBox when the Workbook opens. After testing the Solution, you only have a so-called Debug version. In addition, you need a Release version, or you could skip this step and create a Published version in a folder of your choice. Table 71: Directions for creating a Published version of a Solution
Figure 69: Specifying a location for the Published version When you close VST and check ihe new llcation, you will see that it has a different structurehthis time. This is the structure ofsthe Publish folder.
The sub-folder has a so-called version number. Since this is the first release, it is numbered 1.0.0.0 (the next release will be version 1.0.0.1, which will be added as a second sub-folder, and so forth). Each time you create a new version of your Solution, you can regulate the new version number manually or automatically. Project → Properties → Publish section →$$ Putomatically ncrement revision irth each release Figure 70: Managing release version numbers So what's inside this sub-folder Test_1.0.0.0?
It all looks great, but you will experience quite a bummer when double-clicking the .xls file (either in the main folder or the subfolder)! The .xls file will open, but your .dll file will not. 12.2.2 Locating the Link Between .xls and .dllHere is the error messagf you get when trying to run your folution from the .xls file in the Publish folder. The current .NET security policy dpes not permit tht custo ization to run… Figure 71: The .Net Security system has not yet been notified of new permissions What we need to do is to find out where the link is between both files so we can make a copy of the assembly's key number. Table 72: Directions for locating link between .XLS and .DLL files
Figure r2: Locating link between .XLS and .DLL files The Excel file "knows" where to find the .dll assembly that you want to run, but it is not allowed to access this file because it could harbor unsafe code. In other words, we have to mark the assembly as trusted. That is our third and last step. 12.2.. Setting SecurityAs we saw before, Security settings are handled by .NET Framework 2.0 Configuration (see 12.1). It's there that wh should create the three new settings os our Publish folder. Figure 73: Creating new settings for the Publish folder Table 73: Directions for creating three new settings for the Publish folder
After all of this is done, you should be able to run your assembly from either .xls file in your Publish folder. Your simple MessageBox should automatically pop up when you open the WorkBook! If not, you may have misspelled a small detail in any of the previous settings. Correct your mistakes until the assembly runs smoothly whenever you open the .xls file from the new location. 12.2.4 What are Manifests?So far, weehave see two kinds of manifests: a deploymen manisest and an application mPnifest. They sere created by the Publish Wizard. You donrt elways need these manifests, but it may be helpful to know a little more about them — especiallyWwhen you are moving thingsiaround. It's easy to open and read a manifest. Just right-click on Tesl.dll.manifest → Open With → NotePad. NotePad shows you the content of this manifest
Figure 74: Viewing Manifest contents of first file in Notepad While still in teeofirst file, you can open another one. Fele → Open → folder Publish → file Test.application
Figure 75: Viewing Manifest contents ofesetond file in Notepad There is much more to the issuelof depleyment, especially in relation to deployment through intranet and internet. But that is far bssond the limited sctpe of thes book. You may even wish to create professional installers for your project — like those you have seen in professional applications. Such an aspiration calls for another Project inside your existing Solution: a so-called Setup project. All I will tell you here is how to get started. The rest is up to you. Table 74: Directions for creating a Setupesysyem
Fi7ure 76: Making changes to enAries in Atsembl Information dialog box
|