Walkthrough: Copying a Document to the End User Computer after a ClickOnce Installation
This page is specific to:.NET Framework Version:4.0
Visual Studio 2010
Walkthrough: Copying a Document to the End User Computer after a ClickOnce Installation

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Applies to

The information in this topic applies only to the following project types and versions of Microsoft Office. For more information, see Features Available by Office Application and Project Type.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • 2007 Microsoft Office system

  • Microsoft Office 2010

Using a ClickOnce post-deployment action, you can install document-level Office solutions, and then copy the document to the end user computer. This requires that you modify the application manifest, and re-sign both the application and the deployment manifests before installation.

This walkthrough illustrates the following tasks:

  • Creating an Office solution to deploy.

  • Implementing a post-deployment action that copies a document to the end user's desktop.

  • Modifying the application manifest of the Office solution to run the post-deployment action.

  • Re-signing the application and deployment manifests.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Working with Settings.

Prerequisites

You need the following components to complete this walkthrough:

Creating a New Project

First, create an Excel workbook project.

To create a new Excel project

  • Create an Excel document-level project for the .NET Framework 3.5. Name the project ExcelWorkbook, and save the project to the %USERPROFILE%\Documents\Visual Studio 10\Projects directory. For more information, see How to: Create Office Projects in Visual Studio.

    Visual Studio opens the new Excel workbook in the designer and adds the ExcelWorkbook project to Solution Explorer.

Creating a Class Library Project that Defines the Post-Deployment Action

You must define the post-deployment action in a separate class library. The post-deployment action performs copies the document to the end user computer.

To create a class library for the post-deployment action

  1. In the File menu, point to Add, and then click New Project.

  2. In the Add New Project dialog box, in the Installed Templates pane, click Windows.

  3. In the Templates pane, click Class Library.

  4. Ensure that .NET Framework 3.5 remains selected as the target framework.

  5. In the Name field, type FileCopyPDA, and then click OK.

  6. In Solution Explorer, click FileCopyPDA.

  7. On the Project menu, click Add Reference.

  8. In the Add Reference dialog box, in the .NET tab, click Microsoft.VisualStudio.Tools.Applications.Runtime and Microsoft.VisualStudio.ToolsApplications.ServerDocument, and then click OK.

  9. In the Class1 code file, add the following using or Imports statements to the top of the code file.

    Imports Microsoft.VisualStudio.Tools.Applications.Deployment
    Imports Microsoft.VisualStudio.Tools.Applications
    
    
    
  10. Rename the class to FileCopyPDA, and then add the following code to the FileCopyPDA class. This code indicates that FileCopyPDA class inherits from IAddInPostDeploymentAction.

    Public Class FileCopyPDA
        Implements IAddInPostDeploymentAction
    
    
    
  11. Add the following code to implement the IAddInPostDeploymentAction.Execute method. This code performs the following tasks:

    • Copies the Excel workbook file to the user's desktop if the solution is installed or updated.

    • Changes the _AssemblyLocation property from a relative path to a fully qualified path for the deployment manifest. This is done using the AddCustomization and RemoveCustomization methods.

    • Deletes the file if the solution is uninstalled.

    Sub Execute(ByVal args As AddInPostDeploymentActionArgs) Implements IAddInPostDeploymentAction.Execute
        Dim dataDirectory As String = "Data\ExcelWorkbook.xlsx"
        Dim file As String = "ExcelWorkbook.xlsx"
        Dim sourcePath As String = args.AddInPath
        Dim deploymentManifestUri As Uri = args.ManifestLocation
        Dim destPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
        Dim sourceFile As String = System.IO.Path.Combine(sourcePath, dataDirectory)
        Dim destFile As String = System.IO.Path.Combine(destPath, file)
    
        Select Case args.InstallationStatus
            Case AddInInstallationStatus.InitialInstall, AddInInstallationStatus.Update
                File.Copy(sourceFile, destFile)
                ServerDocument.RemoveCustomization(destFile)
                ServerDocument.AddCustomization(destFile, deploymentManifestUri)
                Exit Select
            Case AddInInstallationStatus.Uninstall
                If File.Exists(destFile) Then
                    File.Delete(destFile)
                End If
                Exit Select
        End Select
    End Sub
    
    
    
Building and Publishing the Solution

Use the Publish Wizard or the Project Page to build and publish the Office solutions to your development computer.

To publish the Excel project

  1. In Solution Explorer, right-click the FileCopyPDA project, and then click Build.

  2. In Solution Explorer, right-click the ExcelWorkbook project, and then click Build.

  3. In Solution Explorer, right-click the ExcelWorkbook project, and then click Add Reference.

  4. In the Add Reference dialog box, click the Projects tab.

  5. Click FileCopyPDA, and click OK.

  6. In Solution Explorer, click the ExcelWorkbook project.

  7. On the Project menu, click New Folder.

  8. Type Data and press the Enter key.

  9. In Solution Explorer, click the Data folder.

  10. On the Project menu, click Add Existing Item.

  11. In the Add Existing Item dialog box, browse to the output directory for the ExcelWorkbook project.

  12. Click ExcelWorkbook.xlsx, and click Add.

  13. In Solution Explorer, click ExcelWorkbook.xlsx.

  14. In the Properties window, change the Build Action property to Content, and the Copy to Output Directory property to Copy if newer.

  15. Publish the ExcelWorkbook project to the c:\publish folder. For more information, see How to: Deploy an Office Solution by Using ClickOnce.

Modifying the Application Manifest

Use the XML editor in Visual Studio to modify the application manifest to run the File Copy post-deployment action.

To add the installation dependencies to the application manifest

  1. Open the c:\publish directory through Windows Explorer.

  2. Open the Application Files folder and then open the ExcelWorkbook_1_0_0_0 folder.

  3. Open the ExcelWorkbook.dll.manifest file in a text editor.

  4. Add following code after the </vstav3:update> element. For the class attribute of the <vstav3:entryPoint> element, use the following syntax: NamespaceName.ClassName. In this example, the namespace and class names are the same, so that the resulting entry point name is FileCopyPDA.FileCopyPDA.

    <vstav3:postActions>
      <vstav3:postAction>
        <vstav3:entryPoint
          class="FileCopyPDA.FileCopyPDA">
          <assemblyIdentity
            name="FileCopyPDA"
            version="1.0.0.0"
            language="neutral"
            processorArchitecture="msil" />
        </vstav3:entryPoint>
        <vstav3:postActionData>
        </vstav3:postActionData>
      </vstav3:postAction>
    </vstav3:postActions>
    
Re-signing the Manifests

The following procedure signs the application manifest and updates the deployment manifest. This ensures that tampered files are not installed on end user computers.

To re-sign the application and deployment manifests

  1. Copy the ExcelWorkbook_TemporaryKey.pfx certificate file from the %USERPROFILE%\Documents\Visual Studio 10\Projects\ExcelWorkbook\ExcelWorkbook solution directory into the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.

  2. Open the Visual Studio command prompt.

  3. Change to the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.

  4. Sign the modified application manifest with the following command:

    mage -sign ExcelWorkbook.dll.manifest -certfile ExcelWorkbook_TemporaryKey.pfx
    

    The message "ExcelWorkbook.dll.manifest successfully signed" appears.

  5. Change to the c:\publish directory.

  6. Update and sign the deployment manifest with the following command:

    mage -update ExcelWorkbook.vsto -appmanifest "Application Files\Ex
    celWorkbook_1_0_0_0\ExcelWorkbook.dll.manifest" -certfile "Application Files\ExcelWorkbook_1_0_0_0\ExcelWorkbook_TemporaryKey.pfx"
    

    The message "ExcelWorkbook.vsto successfully signed" appears.

  7. Copy the ExcelWorkbook.vsto file to the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.

Testing the Post-Deployment Action

The following procedure ensures that the updated manifest installs the Excel workbook and copies the workbook to the end user's desktop.

To test the post-deployment action

  1. Copy the c:\publish directory to a test computer.

  2. Run the Setup.exe program, or if the prerequisites are already installed on the test computer, double-click the ExcelWorkbook.vsto deployment manifest.

    The Microsoft Office Customization Installer appears.

  3. Click Install.

    The Microsoft Office Customization Installer dialog box shows the following message: "The Microsoft Office customization was successfully installed." The Excel workbook is copied to the end user's desktop.

  4. Open the ExcelWorkbook.xlsx file from the desktop.

See Also

Tasks

Concepts

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View