A new sample and video are available which demonstrate packaging a VSTA add-in within a document using System.IO.Packaging. Packaging is also used by Office 2007 documents including the "docx", "docm", "xlsx", and "xlsm" file types. In this sample, both the add-in source code and compiled assembly are packaged into the single file document which can be transferred (ex: e-mailed) and opened by another user who through the single file will have access to the document, compiled add-in and source code- similar to an Office document with a VBA macro project included.
This sample is document-centric, so the add-in is intended only for use with the document it is packaged within. Based on the ShapeAppDynamicProgrammingModelCSharp SDK sample, this sample extends the existing packaging file format of the SDK samples to include the VSTA add-in associated with the document. Benefits of packaging document specific VSTA add-ins within documents include ease of deployment and an intuitive end user experience.
The main code changes made to the SDK sample ShapeAppDynamicProgrammingModelCSharp for packaging are in methods involved with saving and opening documents in the document.cs file. The add-in project associated with the document is originally created in the same folder as the document. A copy of the project and add-in are packaged into the document while the originals stay in place. This allows the add-in project to be updated outside of the document, and logic was added to use the original project and add-in if available. If the project or add-in is no longer available then the internal copy is used. The internal copy is updated every time the document is saved. This provides a more dev oriented experience, allowing the add-in project to be modified outside of the document, but may not be optimal for non-dev end users. The add-in project source code and assembly are packaged within the document so the only required file is the single document file.
The ShapeAppDynamicProgrammingModelCSharp sample was also updated to include seamless non-destructive debugging; a side effect of this is the add-in projects cannot be run directly because they search for a running instance of the host instead of starting a new one. Therefore, to run a DPM packaged project, open the document through the host instead of debugging from a standalone VSTA IDE.
Note, this is not ClickOnce deployment, for information on ClickOnce deployment please refer to the SDK section Securing and Deploying Add-Ins.
Summit: Link to Sample
Summit: Link to Video
MSDN: Add-in Debugging
MSDN: DPM Walkthrough
MSDN: Office Packaging
Apr 07 2009, 01:08 PM