Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Walkthrough: Deploying a Document and an Assembly to a Network 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 so that the document and the assembly are in a folder on a network computer. This type of deployment is known as the network/network 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:

  • Editing the embedded application manifest in a document to point to the assembly.

  • Granting full trust to a Microsoft Visual Studio 2005 Tools for the Microsoft Office System solution assembly that is located in a network 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.

  • Access to a network computer for deployment.

  • 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 "Editing the Embedded Application Manifest".

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.

When you build your solution, the document assumes that the assembly is in the same folder as the document. The location of the assembly is stored in an application manifest that is embedded in the document. If you deploy the document and assembly to different folders, you must edit the embedded application manifest to specify the new assembly path. In the following steps, you will use the ServerDocument class to edit the embedded application manifest in the document to point to the new location of the customization assembly. The code that uses ServerDocument to edit the embedded application manifest must be outside of the Visual Studio Tools for Office project assembly that is associated with document you are deploying.

To edit the embedded application manifest

  1. Create a new Console Application project. For more information, see How to: Create Solutions and Projects.

  2. Add a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime.dll assembly to the new project.

  3. Add the following using statement (C#) or Imports statement (Visual Basic) to the top of the Program.cs or Module1.vb code file.

    Imports Microsoft.VisualStudio.Tools.Applications.Runtime
    

    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    
  4. Add the following code in the Main method to update the embedded application manifest. Replace <full document path> with the full path of the document in its build location on the development computer—for example, <project folder>\bin\debug\WordDeployment.doc. Replace <full assembly path> with the full path of the assembly in the network folder it will be deployed to—for example, \\DeploymentServer\DeploymentFolder\WordDeployment.dll.

    Dim sd As ServerDocument = Nothing
    Try
        sd = New ServerDocument("<full document path>")
        sd.AppManifest.Dependency.AssemblyPath = _
            "<full assembly path>"
        sd.Save()
    Finally
        If Not sd Is Nothing Then
            sd.Close()
        End If
    End Try
    

    ServerDocument sd = null;
    try
    {
        sd = new ServerDocument(@"<full document path>");
        sd.AppManifest.Dependency.AssemblyPath = 
            @"<full assembly path>";
        sd.Save();
    }
    finally
    {
        if (sd != null)
        {
            sd.Close();
        }
    }
    
  5. Build and run the project. The console application updates the assembly path in the embedded application manifest and then closes.

    NoteNote

    Make sure that the document is not open in an instance of Word or the project designer. If the document is open, the attempt to access the document using ServerDocument will fail.

  6. Close the Console Application project.

In the following steps, you will deploy the document and assembly to the same folder on the network computer.

To deploy the solution

  1. Create a folder named DeploymentFolder on a network computer, and share the folder to yourself. For example, if the network computer is named DeploymentServer, the new network share would be \\DeploymentServer\DeploymentFolder. Make sure that the network share has the same name that you specified in the <full assembly path> placeholder when you edited the embedded application manifest in the previous steps.

  2. Copy the document and the assembly from the build output folder (typically <project folder>\bin\debug or <project folder>\bin\release) to the \\DeploymentServer\DeploymentFolder network share.

  3. Open the document in the \\DeploymentServer\DeploymentFolder network share. You will see an error message that states that the customization assembly could not be found or could not be loaded. This is because you have not granted full trust to the document and the assembly in the network folder.

  4. Click OK, and then close the document.

In the following steps, you will grant full trust to the assembly and the document 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 and the document

  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 -m -ag LocalIntranet_Zone -url "<full assembly path>" FullTrust -n "Test_Deployment_Assembly"
    

    Replace <full assembly path> with the full path of the assembly in the network folder—for example, \\DeploymentServer\DeploymentFolder\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. Type the following command to create a new code group that grants full trust to the document and then press ENTER. You must grant full trust to the document because you as the end user will open it from the network folder. Documents do not require full trust if they are on the end user computer.

    %windir%\Microsoft.NET\Framework\v2.0.50727\caspol -m -ag LocalIntranet_Zone -url "<full document path>" FullTrust -n "Test_Deployment_Document"
    

    Replace <full document path> with the full path of the document in the network folder—for example, \\DeploymentServer\DeploymentFolder\WordDeployment.doc.

    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 have completed this walkthrough.

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

  6. On your development computer, open the document in the \\DeploymentServer\DeploymentFolder network folder and verify that the message appears.

  7. Save the document to a folder the development computer, and then close the document.

  8. Open the document on the development computer, and verify that the message appears.

    This works because the embedded application manifest includes the full path of the assembly on the network computer. If you did not edit the path of the assembly in the embedded application manifest, the solution would run only if you open the document from the network folder.

  9. Click OK, and then close the document.

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.