Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Walkthrough: Deploying a Document and an Assembly to a Local Folder

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

  • Microsoft Office 2003

This walkthrough demonstrates how to deploy a document-level customization to a new folder on your development computer, so that the document and the assembly are located in the same folder. This type of deployment is known as the local/local deployment model. For more information about options for deploying your solution, see Deployment Models. For more information about document-level customizations, see Office Solutions Architecture Overview.

Tasks illustrated in this walkthrough include:

  • Granting full trust to a Microsoft Visual Studio 2005 Tools for the Microsoft Office System solution assembly that is located in a local folder.

To complete this walkthrough, you will need:

  • Visual Studio Tools for Office.

  • Microsoft Office Word 2003 or Microsoft Office Excel 2003.

    NoteNote

    This walkthrough assumes that you are deploying a Word solution. If you want to perform the walkthrough with an Excel solution, replace the name of the Word project with the name of your Excel project in all code examples.

  • Administrator privileges on the development computer, so you can set the security policy.

In the following steps, you will create a basic Visual Studio Tools for Office solution to deploy. If you already have a solution that you want to deploy, you can skip this section and proceed to "Deploying the Solution".

To create a solution to deploy

  1. Create a Word Document project with the name WordDeployment. Make sure that Create a new document is selected. For more information, see How to: Create Visual Studio Tools for Office Projects.

  2. In Solution Explorer, right-click the ThisDocument (for Word) code file and click View Code.

  3. Add the following code in the ThisDocument_Startup event handler. This code displays a message when the document opens, which will make it easy to verify whether the solution has been deployed successfully.

    MessageBox.Show("The deployment is successful")
    

    MessageBox.Show("The deployment is successful");
    

    For more information about the Startup event, see Visual Studio Tools for Office Project Events.

  4. Press F5 to build and run the project. Verify that the message appears.

In the following steps, you will deploy the document and assembly to a new folder on your development computer.

To deploy the solution

  1. Create a folder named TestDeploy at the root of the Windows system drive (%SystemDrive%). For example, if your system drive is C, the directory would be C:\TestDeploy.

  2. Copy the document and assembly from the build output folder (typically <project folder>\bin\debug or <project folder>\bin\release) to the %SystemDrive%\TestDeploy folder.

  3. Open the document in the %SystemDrive%\TestDeploy folder. You will see an error message that states that the current .NET security policy does not permit the customization to run. This is because you have not granted full trust to the assembly yet.

  4. Click OK, and then close the document.

In the following steps, you will grant full trust to the assembly in your .NET Framework 2.0 security policy. This walkthrough uses the Code Access Security Policy tool (Caspol.exe) to grant full trust to the assembly. For more information about using Caspol.exe, see Code Access Security Policy Tool (Caspol.exe) and Configuring Security Policy Using the Code Access Security Policy Tool (Caspol.exe).

Security noteSecurity Note

These are basic steps for setting a security policy based on URL evidence for the purpose of completing this walkthrough. Do not use these steps to grant trust to assemblies in a real-world solution if you are not certain that the location is safe and secure. You should also base the security of a real-world solution on more evidence than the URL of the assembly. For more information, see Security Requirements to Run Office Solutions.

To grant full trust to the assembly

  1. Click Start, point to All Programs, point to Accessories, and then click Command Prompt.

  2. Type the following command to create a new code group that grants full trust to the assembly.

    %windir%\Microsoft.NET\Framework\v2.0.50727\caspol -u -ag All_Code -url "<full assembly path>" FullTrust -n "Test_Deployment"
    

    Replace <full assembly path> with the full path of the assembly on the development computer—for example, C:\TestDeploy\WordDeployment.dll.

    The -n parameter specifies a name for the new code group. This parameter is not required, but specifying a label makes it easier to later identify and remove the new code group after you complete this walkthrough.

  3. Type yes when prompted to confirm that you want to perform the operation, and press ENTER.

  4. Open the document in the %SystemDrive%\TestDeploy folder and verify that the message appears.

  5. Click OK, and then close the document.

You can also deploy the document and the assembly to different folders on the same computer, or you can deploy the document and the assembly to a network folder. For more information, see the following walkthroughs:

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft