TEAMFLY Team-Fly ® Jeffrey Cogswell Developing Visual Studio ® .NET Macros and Add-Ins Dear Valued Customer, We realize you’re a busy professional with deadlines to hit. Whether your goal is to learn a new technology or solve a critical problem, we want to be there to lend you a hand. Our primary objective is to provide you with the insight and knowledge you need to stay atop the highly competitive and ever- changing technology industry. Wiley Publishing, Inc., offers books on a wide variety of technical categories, including security, data warehousing, software development tools, and networking — everything you need to reach your peak. Regardless of your level of expertise, the Wiley family of books has you covered. • For Dummies ® – The fun and easy way ™ to learn • The Weekend Crash Course ® –The fastest way to learn a new tool or technology • Visual – For those who prefer to learn a new topic visually • The Bible – The 100% comprehensive tutorial and reference • The Wiley Professional list – Practical and reliable resources for IT professionals The book you now hold, Developing Visual Studio ® .NET Macros and Add-Ins, is your complete guide to customizing the Visual Studio development environment. With this book, you will be able to automate routine tasks, build custom interfaces, use Office objects, and much more — using any Visual Studio- enabled language — to make this powerful development tool even more responsive and better suited to the needs of your development process. Our commitment to you does not end at the last page of this book. We’d want to open a dialog with you to see what other solutions we can provide. Please be sure to visit us at www.wiley.com/compbooks to review our complete title list and explore the other resources we offer. If you have a comment, suggestion, or any other inquiry, please locate the “contact us” link at www.wiley.com. Thank you for your support and we look forward to hearing from you and serving your needs again in the future. Sincerely, Richard K. Swadley Vice President & Executive Group Publisher Wiley Technology Publishing WILEY advantage The Developing Visual Studio ® .NET Macros and Add-Ins Jeffrey Cogswell Developing Visual Studio ® .NET Macros and Add-Ins Publisher: Joe Wikert Senior Editor: Ben Ryan Developmental Editor: Adaobi Obi Tulton Editorial Manager: Kathryn Malm Production Editors: Micheline Frederick/Felicia Robinson Media Development Specialist: Megan Decraene Text Design & Composition: Wiley Composition Services This book is printed on acid-free paper. ∞ Copyright © 2003 by Jeff Cogswell. All rights reserved. Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rose- wood Drive, Danvers, MA, 01923, (978) 750-8400, fax (978) 646-8700. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN, 46256, (317) 572-3447, fax (317) 572-4447, e-mail: permcoordinator@wiley.com. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley Publishing logo, and related trade dress are trademarks or registered trademarks of Wiley Publishing, Inc., in the United States and other countries, and may not be used without written permission. Visual Studio is a trademark or registered trademark of Microsoft Corporation. All other trade- marks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data: ISBN: 0-471-23752-3 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 To all the .NET programmers who are continually seeking knowledge. [...]... Models Visual Studio Packages Visual Studio Project Types Accessing Project Types Not Supported by the Macros IDE Accessing the Project Object Accessing Visual Basic and C# Projects Accessing C++ Projects Macro IDE Automation Model Moving Forward 98 99 10 0 10 1 10 2 10 2 10 3 10 4 10 4 10 6 10 7 10 8 10 9 11 2 11 3 Part 2 Enhancing Visual Studio 11 5 Chapter 6 Introducing Add-ins About Add-ins 11 7 11 7 Startup and. .. Pages Creating Tool Windows Add-ins and the Command System Wizards Add-ins Are COM Components Creating an Add-in Using the Wizard Building and Running the Add-in 11 9 12 0 12 1 12 3 12 4 12 4 12 5 12 6 12 9 13 0 13 6 Managing Add-ins Moving Forward Chapter 7 13 7 13 8 Creating Add-ins for the IDE Building an Add-in in C++ Including a GUI with Your Add-in 13 9 13 9 14 0 Working with Commands Using the Forms Library... Introduction xvii Part 1 Automating Your Work 1 Chapter 1 All about Macros and Add-ins What Are Macros and Add-ins? Why Use Macros and Add-ins? Automating Your Work with Macros Enhancing the IDE with Add-ins Online Help for Macros and Add-ins Other Ways to Customize Visual Studio NET 3 4 4 5 7 8 9 Manipulating the Windows Managing the Toolbars and Commands Customizing the Menus 10 17 22 Moving Forward... Tool Window Using the Form Designer with a Tool Window 14 1 14 1 14 5 15 3 Moving Forward Chapter 8 15 9 Life Cycles, Debugging, and Satellite DLLs The Life Cycle of an Add-in Debugging an Add-in 16 1 16 1 16 2 Keeping the Registry Clean Debugging the Command-Line Version Debugging the Command-Line Add-in Setting Up Multiple Debug Configurations 16 3 16 3 16 4 16 5 ix x Contents Creating a Satellite DLL for Resources... issues relating to macros, add-ins, and NET development in general ■ ■ Links to more add-ins and macros that you can download ■ ■ And much more The Web site was designed to help you, the software developer, get the most possible out of Visual Studio NET as you develop add-ins and macros Please join us! xxi PA R T One Automating Your Work CHAPTER 1 All about Macros and Add-ins Macros and add-ins are nothing... Team-Fly® Introduction Welcome to Macros and Add-ins This is a book about developing macros and add-ins for Visual Studio NET Every programmer who uses Visual Studio NET, regardless of the type of project he or she is developing, and regardless of his or her skill level, sooner or later wonders: Why can’t Visual Studio NET do such -and- such? Or: Wouldn’t it be nice if Visual Studio NET had this feature I’m... Enough VB.NET VB.NET Subroutines and Functions VB.NET Variables Arrays in VB.NET Strings in VB.NET VB.NET Control Structures 27 29 30 34 36 40 Conditional Statements Loop Statements Exceptions Classes in VB.NET Other VB.NET Topics Moving Forward 40 41 43 44 46 48 vii viii Contents Chapter 3 Introducing the Visual Studio Macro IDE The Macro System and the Main IDE Macro Development Divisions 49 49 51 Projects... macros, you can use a simple recorder feature Most of the Microsoft products (including Visual Studio NET) allow you to easily record a sequence of keystrokes and menu commands to a macro, and then play it back later But if you want to write more sophisticated macros, you can open up the Visual Studios Macro IDE and develop macros using a full-featured IDE that looks much like the standard Visual Studio. .. Chapter 6, “Creating Add-ins for the IDE.” Visual Studio NET contains a project wizard called Visual Studio NET Add-in Project This wizard simplifies the process of creating an add-in by providing you with a starting point Further, Visual Studio NET gives you an interesting way of developing 7 8 Chapter 1 add-ins When you run an add-in project opened in Visual Studio NET, a new Visual Studio NET process... creating an add-in starting in Chapter 6, “Creating Add-ins for the IDE.”) Online Help for Macros and Add-ins One of the most important references you will want to use when developing your macros and add-ins is the online help that accompanies Visual Studio NET There are dozens of objects and classes available to you for manipulating the Visual Studio NET IDE, and these classes are all fully documented in . Enhancing Visual Studio 11 5 Chapter 6 Introducing Add-ins 11 7 About Add-ins 11 7 Startup and Shutdown 11 9 Invoking Your Add-in 12 0 Interacting with the IDE 12 1 Creating Custom Options Pages 12 3 Creating. Assembly 10 0 .NET and OLE/COM 10 1 Globally Unique Identifiers 10 2 Building an Assembly from a COM Component 10 2 Macro and Add-in Models 10 3 Visual Studio Packages 10 4 Visual Studio Project Types 10 4 Accessing. xvii Part 1 Automating Your Work 1 Chapter 1 All about Macros and Add-ins 3 What Are Macros and Add-ins? 4 Why Use Macros and Add-ins? 4 Automating Your Work with Macros 5 Enhancing the IDE with Add-ins