Udostępnij za pośrednictwem


How to: Build and Run the ShapeAppBasicCSharp Sample

The ShapeAppBasicCSharp sample demonstrates how to extend the ShapeAppCSharp sample host application to load and unload add-ins.

After you build and run ShapeAppBasicCSharp, you can load an add-in that is included with the sample. To build and run ShapeAppBasicCSharp, perform the following steps:

  1. Install Visual Studio Tools for Applications.

  2. Extract ShapeAppBasicCSharp.

  3. Open ShapeAppBasicCSharp in Visual Studio and build it.

  4. Register ShapeAppBasicCSharp. This enables you to build and debug the sample add-in, and to use the project templates that are included with ShapeAppBasicCSharp to create your own add-ins.

  5. Build the sample add-in.

  6. Load the sample add-in into ShapeAppBasicCSharp.

  7. (Optional) Unregister ShapeAppBasicCSharp. Doing this removes the registry entries that let you build and debug the sample add-in, and also removes the entries that let you use the project templates that are included with ShapeAppBasicCSharp.

For more information about the ShapeApp samples, see ShapeApp Samples (Visual Studio Tools for Applications).

To extract ShapeAppBasicCSharp

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

    Note

    Although you can extract ShapeAppBasicCSharp to any folder, the following procedures and the walkthroughs in the Visual Studio Tools for Applications documentation assume that you extract ShapeAppBasicCSharp to the drive:\ShapeAppSamples\ShapeAppBasicCSharp folder.

  2. Open the Visual Studio Tools for Applications samples folder.

    By default, the samples folder is located at %ProgramFiles%\Visual Studio Tools for Applications 2.0 SDK\build number\Visual Studio Tools For Applications\Samples on 32-bit versions of Windows, or at %ProgramFiles(x86)%\Visual Studio Tools for Applications 2.0 SDK\build number\Visual Studio Tools For Applications\Samples on 64-bit versions of Windows.

  3. Right-click the ShapeAppBasicCSharp.zip file, and then click Extract All.

    Note

    This step assumes that your system is set to open .zip files using Compressed (zipped) Folders. If your system is set to open .zip files with another program, follow the instructions of that program to extract the contents of ShapeAppBasicCSharp.zip.

  4. Follow the instructions in the Extract Compressed (Zipped) Folders wizard to extract the contents of ShapeAppBasicCSharp.zip to the drive:\ShapeAppSamples\ShapeAppBasicCSharp folder.

To build ShapeAppBasicCSharp

  1. Start Visual Studio 2008. If you are using Windows Vista as your operating system, start Visual Studio 2008 by using the Run as Administrator option.

  2. On the File menu, point to Open, and then click Project/Solution.

  3. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppBasicCSharp folder.

  4. Select the ShapeAppBasicCSharp.sln file, and then click Open.

  5. On the Build menu, click Build Solution. Verify that the solution builds without errors.

  6. On the File menu, click Close Solution.

To register ShapeAppBasicCSharp

  1. Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.

  2. Run the following command.

    cd "%SystemDrive%\ShapeAppSamples\ShapeAppBasicCSharp"
    

    Note

    If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that registers ShapeAppBasicCSharp can be run only in a 32-bit Command Prompt window.

  3. Type the following command to run the SetupShapeAppBasicCSharp.js script file. This script file registers ShapeAppBasicCSharp with Visual Studio Tools for Applications and configures the project templates so that they can be used from Visual Studio 2008.

    cscript SetupShapeAppBasicCSharp.js
    

    For more information about registering host applications, see Registering the Host Application.

    Note

    This command might require several minutes to complete.

    Note

    Each version of the ShapeAppCSharp sample provides a setup script. All setup scripts write to the same location in the registry. Therefore, you can only use the setup script to register one version of the ShapeAppCSharp sample application at a time.

To build the sample add-in

  1. On the File menu, point to Open, and then click Project/Solution.

  2. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppBasicCSharp\sample AddIns\CSharp folder.

    Note

    The following instructions assume that you are building the Visual C# version of the add-in. For a Visual Basic version of the add-in, see the drive:\ShapeAppSamples\ShapeAppBasicCSharp\sample AddIns\VisualBasic folder.

  3. Select the ShapeAppCSharpAddIns.sln file, and then click Open.

  4. On the Build menu, click Build Solution. Verify that the solution builds without errors.

    When you build the solution, the add-in assemblies are automatically copied as follows:

    For Windows XP and Windows Server 2003:

    • ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\My Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.

    • ShapeAppCSharpDocAddIn.dll is copied to %UserProfile%\My Documents\ShapeAppCSharp\DocAddIns\ShapeAppCSharpDocAddIn.

    For Windows Vista:

    • ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.

    • ShapeAppCSharpDocAddIn.dll is copied to %UserProfile%\Documents\ShapeAppCSharp\DocAddIns\ShapeAppCSharpDocAddIn.

    ShapeAppBasicCSharp searches for add-ins in this directory.

  5. On the File menu, click Close Solution.

To load the add-in into ShapeAppBasicCSharp

  1. On the File menu of Visual Studio, point to Open, and then click Project/Solution.

  2. In the Open Project dialog box, navigate to the drive:\ShapeAppSamples\ShapeAppBasicCSharp folder.

  3. Select the ShapeAppBasicCSharp.sln file, and then click Open.

  4. Press F5.

  5. Verify that the message "Document Created" appears, and then click OK.

    This verifies that the add-in has loaded correctly.

  6. Verify that the message "Shape Location Changed" appears, and then click OK.

  7. Verify that the message "Shape Added to the drawing" appears, and then click OK.

    This demonstrates the use of event handlers in the add-in events defined in the host application.

  8. Verify that the message "Incorrect point values: X = -30, Y = -30" appears, and then click OK.

    This demonstrates the use of a custom exception.

  9. Verify that the message "ShapeApp Managed Sample with basic VSTA integration" appears, and then click OK.

    This demonstrates the use of a static member in the object model.

  10. Close ShapeAppBasicCSharp.

To unregister ShapeAppBasicCSharp

  1. Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.

  2. Run the following command.

    cd "%SystemDrive%\ShapeAppSamples\ShapeAppBasicCSharp"
    

    Note

    If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that unregisters ShapeAppBasicCSharp can be run only in a 32-bit Command Prompt window.

  3. Type the following command to run the RemoveShapeAppCSharp.js script file. This script file removes registry entries that let you to build and debug the sample add-in, and also removes entries that let you use the project templates that are included with ShapeAppBasicCSharp.

    cscript RemoveShapeAppCSharp.js
    

    Note

    This command might require several minutes to complete.

See Also

Tasks

How to: Build and Run the ShapeAppCSharp Sample

How to: Build and Run the ShapeAppMacroRecordingCSharp Sample

How to: Build and Run the ShapeAppDynamicProgrammingModelCSharp Sample

How to: Build and Run the ShapeAppClickOnceCSharp Sample

How to: Build and Run the ShapeAppBasicMFC Sample

Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp

Concepts

ShapeApp Samples (Visual Studio Tools for Applications)