Back to description
Having a good background in Visual Studio and knowing its history and features can help you understand all the chapters... more
Having a good background in Visual Studio and knowing its history and features can help you understand all the chapters in this book better. Of course, such an understanding is a prerequisite for reading this book, but it is likely that readers have acquired their knowledge from different resources and from their daily experience with this IDE, and therefore may be unfamiliar with some aspects of it. This chapter describes a few things that may be helpful as you read the book.
First, I’ll provide a short history of Visual Studio and the main features and enhancements in each of its versions. After that I’ll cover Visual Studio 2008 (code-named Orcas) and its new features and requirements, and the installation process. Then, after an overview of the Visual Studio IDE, you will learn about extensibility in Visual Studio and the Visual Studio SDK.
... less
After reviewing the history of Visual Studio, its features, and its main elements in Chapter 1, it’s time to look... more
After reviewing the history of Visual Studio, its features, and its main elements in Chapter 1, it’s time to look at another basic topicthe Microsoft .NET Framework. Visual Studio targets the .NET Framework and supports its programming languages and technologies, so it seems reasonable to dedicate a chapter to this framework. Here you will find a brief introduction to its architecture, programming languages, and technologies, and examine its correlation with Visual Studio.
The .NET Framework is important in this book for two reasons:
Developers want to extend Visual Studio to simplify their daily development tasks with it, in order to develop something with .NET programming languages and technologies. For example, you may want to write an add-in to automate some coding tasks with C#, or perhaps you need to write a visualizer to debug an ASP.NET cache. Yet another reason may be to write a macro to create a fixed layout for a Windows Presentation Foundation application. In order to extend Visual Studio for any of these scenarios, you have to know the .NET Framework very well.
You use .NET to extend Visual Studio! In every chapter of this book, I apply .NET programming languages, programming techniques, and various concepts of .NET technologies to illustrate the topics; readers definitely should have a good background in the .NET Framework.
Therefore, this chapter covers the following main topics:
The .NET Framework, including its available versions and their features
The architecture of the .NET Framework
Available programming languages in .NET
Technologies included in the .NET platform
Integration between the .NET Framework and Visual Studio 2008
Let’s begin with an introduction to Microsoft .NET.
It’s time to wade in and get your feet wet with the main topic of this book: extending Visual Studio.... more
It’s time to wade in and get your feet wet with the main topic of this book: extending Visual Studio. In this chapter you’ll look at three common options for extending Visual Studio: macros, add-ins, and visualizers.
Before getting into a detailed discussion about these extension options, it may be worthwhile to take a quick tour so you can see what they are. Some readers may not be aware of what these extensions really do or may not have a detailed understanding of them. This tour also provides a few simple examples; later you’ll get a full discussion of all extension options, including real-world examples.
You may see some new material throughout this chapter and in the sample code, but don’t worry. I’ll describe the content on a need-to-know basis. If you have questions, keep in mind that you’ll revisit this subject again in subsequent chapters and more detailed information will be provided.
Here’s what you’ll discover in this chapter:
Different options to extend Visual Studio
A short introduction to macros, including an example
A short introduction to add-ins, including an example
A short introduction to visualizers, including an example
How to use the MSDN library and VS Help to learn more about extension options
After finishing this chapter, you’ll move on to the main part of this book and go beyond the basic information presented in the first three chapters.
After the opening introductory chapters, I want to discuss add-ins and some topics related to them.... more
After the opening introductory chapters, I want to discuss add-ins and some topics related to them. In my experience, add-ins have been the most common way to extend Visual Studio during the last decade or so.
In addition to add-ins, this chapter discusses some general topics about Visual Studio Extensibility, and uses add-ins to apply them. These topics are something you’ll need to know for other extensibility options. The topic of this chapter, the automation model, is important because you need to use it for macros and VSPackagesand because it’s a general API for Visual Studio Extensibility.
Therefore, reading this chapter can be helpful for those who want to dive into the details of topics in subsequent chapters. For now, let’s get to a major theme of this chapter, Development Tools Extensibility (DTE), which will remain an important topic for the rest of the book. What is DTE? I’ll answer that completely in this chapter, but at this point I want to mention that DTE is an API that has been a part of Visual Studio for a long time and is actually the main representation of the automation model in code. Microsoft has improved it over the years in each new version.
Development Tools Extensibility enables you to get access to different properties, methods, and events of the Visual Studio IDE in order to manipulate it. Obviously, this is important for extending Visual Studio.
This chapter provides a general overview and discussion about the automation model based on Development Tools Extensibility (DTE). In subsequent chapters, you’ll learn more about each major aspect of the automation model.
Here’s what is covered in this chapter:
General overview of the automation model and its concept
The architecture of the automation model and Development Tools Extensibility (DTE)
Main aspects of the automation model and a short description of each
What can and can’t be done with the automation model
The automation model and the Macros IDE
In preparation for the longer discussion of Visual Studio Extensibility in later chapters, we’ll start with an introduction to the automation model and Development Tools Extensibility, one of your most powerful tools throughout the book.
Note that this chapter is primarily a theoretical, general discussion about a broad topic and is designed just to get you started with it. A more detailed discussion about each aspect of the automation model and DTE APIs can be found in the rest of the book.
In Chapter 3 you got a quick overview of building a very simple add-in for Visual Studio. As you discovered there,... more
In Chapter 3 you got a quick overview of building a very simple add-in for Visual Studio. As you discovered there, the first step to create an add-in is to choose the appropriate project template and then provide a name for your add-in. This simple process will invoke the Visual Studio Add-in Wizard.
The topic of this chapter is that wizard. At first glance, it may seem like this wizard doesn’t play a very important role in building an add-in, and dedicating a chapter to it may seem like a waste of time. In fact, however, this wizard accomplishes more than meets the eye, and it’s worthwhile to know more about it.
The Add-in Wizard collects your selections for building an add-in and then generates necessary code templates and configuration files, configuring the local machine to run your add-in. These steps would take a great deal of time if you, as a developer, had to do them manually, but thanks to the wizard you can create the best code for this purpose in a few seconds.
A developer who just wants to create a simple add-in doesn’t care about the behind-the-scenes part of this wizard, but a professional developer who buys and reads this book should be interested to know what’s going on there. This chapter is the first in a series that covers add-ins and discusses how to build an add-in. In this chapter you’ll learn the first steps in the process.
Here are the major topics that you’ll read about in this chapter:
What you should do before building an add-in
Different steps in the Add-in Wizard
What happens behind the scenes for each step of the wizard
A general overview of what the wizard does and the generated solution and code
A short introduction to shared add-ins and the Shared Add-in Wizard, which can be used to create add-ins for Microsoft Office products
Even though you can write all the code that the Add-in Wizard generates for you, you’ll probably agree that this would take too much of your time. Therefore, let’s get started with the first topic: the pre-build requirements to create an add-in.
After executing the Add-in Wizard to generate a starting code for your add-in, now you need to begin customizing this... more
After executing the Add-in Wizard to generate a starting code for your add-in, now you need to begin customizing this code and implementing your code logic for the add-in. Without your own code implementation, add-ins do not provide any capability and don’t work at all.
The goal of this chapter, therefore, is to learn the anatomy of an add-in in order to be able to work with and develop them. Add-ins are just an implementation of a programming interface, and nothing more. Even though this implementation is sometimes simple, there are many complicated add-ins available that interact with the user interface and extend different aspects of Visual Studio.
Understanding the anatomy of an add-in is a key part of successfully developing add-ins because it’s like the providing the foundation of a building that may look simple but support a very complicated structure. All add-ins (without exception) have the same structure. Some of them may be simple and others may be complicated. If you know the structure, then you can follow up the code for all add-ins easily.
The anatomy of an add-in consists of two main parts: an implementation of an interface and a configuration file.
This chapter covers both parts of the add-in, includes the following topics:
The structure of an add-in class
A closer look at each event in add-in implementation
The purpose of an add-in configuration file and its structure
How to add a Toolbar menu item for an add-in
How to run an add-in from the command line
How to add an add-in to a toolbar
A brief look at shared add-ins and their similarities to and differences from Visual Studio add-ins
After reading this chapter, you should be able to develop simple add-ins easily. In the following chapters, you’ll learn about the main parts of the automation model so you can use them to write more enhanced add-ins.
Solutions, projects, and project items are the fundamental parts of development in Visual Studio,... more
Solutions, projects, and project items are the fundamental parts of development in Visual Studio, and you always need to deal with them in order to develop an application.
Therefore, Document Tools Extensibility (DTE) has to provide a rich set of APIs to work with these main elements, and it does! This chapter covers solutions, projects, project items, and other related material.
The development model and structure in Visual Studio have changed over the last decade, but the structure has remained constant since the birth of .NET technology. We’ll focus now on this structure, with its solutions, projects, and project items.
Most extensibility scenarios share the common purpose of using these elements in order to get something done. Using the automation model, you can do whatever you want with these elements in the Visual Studio IDE, including creating solutions and projects, adding project items, removing these elements, and much more.
In this chapter you’ll learn about the following topics;
An introduction to the structure of solutions, projects, and project items in Visual Studio development
The Solution object, including a detailed discussion about its properties and methods
The Project object, with details about its properties and methods
The ProjectItem object, including a discussion about working with project items
Visual Studio events related to solutions, projects, and project items
Each of these topics is covered in a practical way. That is, we will go over them one by one, looking at common scenarios and applications for each, including sample source codes.
We begin the chapter with a short background about the concepts you’ll deal with frequently in the chapter.
The other common scenario for writing an add-in and extending the Visual Studio environment is to extend editor functionality... more
The other common scenario for writing an add-in and extending the Visual Studio environment is to extend editor functionality and manipulate active documents and their content.
You often need to change something in your code automatically or update the text in your windows in order to perform a task. For example, you may want to add a method to the top of a class file.
In general, because the most common task in Visual Studio is coding, it’s predictable that extending the editor and coding features, and providing better and easier ways to use them, is a main feature of Visual Studio extensibility.
The code model is one of several automation models that enable you to access appropriate APIs in order to work with coding features and manipulate code and text in documents. Besides the project model (described in Chapter 7), the code model is a helpful part of the automation model that’s been enhanced in Visual Studio 2005 and 2008 to offer more features.
The main topic of this chapter (and Chapter 9) is the code model and how to manipulate text and code in windows. In this chapter you’ll read about the following topics:
An introduction to the code model
The Documents collection
The Document class
Document
The TextSelection, TextPoint, EditPoint, VirtualPoint, and TextDocument interfaces
How to use DTE objects to manipulate texts
As in Chapter 7, these topics are covered in a practical way, including common real-world scenarios and related code samples.
In Chapter 8 you learned how to manipulate the text in the editors and documents. That was a general case,... more
In Chapter 8 you learned how to manipulate the text in the editors and documents. That was a general case, because you were working with text content without being concerned about its meaning, but what about the programming code?
In Visual Studio you usually write code and don’t use it as an editor for text data (who wants to pay for Visual Studio licenses to edit pure text data?!). Therefore, predictably, you need to extend your coding capabilities. This is a common goal of many add-ins for Visual Studio, such as Refactor and ReSharper.
The code model enables you to manipulate programming code and extend Visual Studio to modify it on-the-fly. This part of the automation model provides a set of APIs for working with different pieces of code such as classes and functions. You’ll likely agree that it’s not logical to get the code as pure text and then apply string manipulation functions to modify it every time you want to change something in your code. This would also be hard to implement (just as string manipulations are hard to implement).
In this chapter, you’ll learn all about this and how to manipulate your programming code. While this is the main topic of the chapter, you’ll also read about other topics related to building solutions and projects and manipulating your build process. Chapter 21 is dedicated to MSBuild, the Microsoft build engine for custom and automated builds, but things work a bit differently here, and you’ll learn how to use the automation model to manipulate your build processes.
In a nutshell, this chapter covers the following:
The CodeModel and FileCodeModel interfaces
Different code element interfaces
How to manipulate the code with code model objects
The SolutionBuild interface
So far you’ve just seen how to manipulate some abstract elementswe haven’t yet covered anything about... more
So far you’ve just seen how to manipulate some abstract elementswe haven’t yet covered anything about the user interface and what end users see. A big part of the automation model, however, is dedicated to manipulating the user interface (also abbreviated as UI for simplicity).
This topic can be grouped in three smaller topics:
Adding user interface elements to add-ins in order to get user inputs and options and implement the logic behind the add-in. This makes your add-ins more powerful and user friendly. Interacting with users and responding to their choices make your add-ins professional and enables them to behave in the way that users expect. Up until now, the preceding chapters have just used simple MessageBox dialogs to show any output, because this was a quick and easy way to display information to users, but real life isn’t limited to this option, and of course you need to be able to add user interface elements such as Windows Forms and user controls to your add-ins.
Manipulating the user interface elements in Visual Studio designers. You also need to be able to access some information about Windows Forms and the controls on them in Visual Studio designers to extend their behavior or change it.
Working with common Visual Studio windows such as Toolbox, Output, Task List, and Error List. These are considered separate parts in the automation model, and some APIs are dedicated to working with them. Because these windows are commonly used, it’s clear that you need to be able to manipulate them in extensibility scenarios, so you need to know their APIs to some extent.
These main three topics comprise the fundamentals of this chapter, and I cover them one by one by dividing them into smaller subtopics and giving a detailed discussion of each. After reading this chapter, you should have a good understanding of the automation model and writing common add-ins; then, in the next a few chapters, you’ll learn about some related topics that will help you write more professional add-ins.
Here are the main things we’ll cover in this chapter:
How to add different user interface elements to your add-ins
Adding menu items to Visual Studio IDE for your add-ins
Adding toolbar items for your add-ins
How to manipulate Windows Forms and the user controls for them
Working with Visual Studio windows such as the Command window, the Output window, and the Task List.
Let’s get started.
All good professional software has options for configuration, and tools that enable users to customize the application.... more
All good professional software has options for configuration, and tools that enable users to customize the application. You’re already familiar with options menu items in many applications and no doubt always head there to change the behavior of an application. We need the same capability for Visual Studio add-ins, because when it comes to real-world scenarios, we need to enable our end users to configure the add-in based on their requirements and get the best performance from it.
However, because Visual Studio is our host application when writing add-ins, it doesn’t seem like a good idea to create a separate options page for our add-ins and implement a lot of code to displaypossibly creating add-ins inconsistent with the environment.
In Visual Studio, an excellent options page is located in the Tools menuone that enables you to configure Visual Studio behavior. All the extensions to Visual Studio use this page for their configuration. Add-ins aren’t an exception, and it’s strongly recommended that you make your options a part of the options page in Visual Studio in order to maintain consistency.
This chapter shows you how to create and customize a page in the Options dialog for your add-ins in order to make it configurable. Included in this chapter are the following:
A quick overview of how to create a Tools Options page for add-ins
How to implement an options page for an add-in
How to configure an add-in to use the options page
This isn’t a broad or complicated topic, so you can learn it quickly, and then easily apply its content in real-world scenarios.
Debugging and testing are two of the main stages in software development that all developers have encountered many times... more
Debugging and testing are two of the main stages in software development that all developers have encountered many times in their programming life. Almost all software has bugs and exceptions that need to be debugged and solved before deployment. You already know these principles from software development textbooks so it isn’t necessary to go over the importance of debugging and testing.
What I want to say here, however, is that writing add-ins is no exception to this principle: You need to debug and test your add-ins before deploying them as well. In this case it’s even more important, because a simple bug or exception in an add-in can prevent the whole environment from working, even though the structure of Visual Studio and its mechanism to load and manage add-ins try to avoid this and run add-ins in a way that can’t damage the IDE. However, debugging, exception handling, and testing your add-ins are still mandatory.
If you’ve written an add-in, how can you test it to make sure it works fine? How can you debug an exception to determine the source of the problem? How can you handle an exception in an appropriate exception-handling mechanism to avoid any problem for the add-in?
All these topics are important for you as a developer, and this chapter aims to teach you how to achieve these goalshow to debug your add-ins, how to handle exceptions, and how to test add-ins before deployment to ensure that they work.
Normally you debug your .NET applications that are DLL files in the Visual Studio IDE with several debugging options. You can do this easily in the same environment, but add-ins are a little different, and some specific techniques should be applied to debug them. You probably would agree that it’s not logical to write an add-in and deploy it to see how it works before writing a lot of code to show exceptions in the user interface. This would be a very time-consuming task. The importance of this chapter is that it teaches you how to apply specific techniques to debug your add-ins easily in a shorter amount of time, even though these techniques should be a part of an experienced .NET developer’s knowledge of debugging with Visual Studio.
The following list highlights the main topics that you’ll encounter in this chapter:
A brief description of debugging and testing add-ins
How to debug add-ins
How to handle errors and exceptions
How to test your add-ins
You should read this chapter carefully because it can help you a lot when developing add-ins.
Generally, the last stage of developing an add-in is deploying it and enabling users to install and apply it easily.... more
Generally, the last stage of developing an add-in is deploying it and enabling users to install and apply it easily. Deployment is an important stage of software development, and important enough to warrant its own chapter.
The process of deploying an add-in on a user’s machine isn’t complicated, and you can do it easily. For the machine on which you develop the add-in, Visual Studio does the job and deploys the add-in for the IDE, but for other machines you need to copy necessary files to appropriate paths to enable the add-in on those machines.
Add-ins are COM components, and previously they had to be registered on all machines that wanted to host them; otherwise, they didn’t work. Now, however, you can simply copy two files to appropriate paths to enable them. For this task, .AddIn files come into play and do the job for you, configuring the add-in to work with the Visual Studio IDE easily.
You need to have an appropriate Visual Studio version installed on the machine. For example, if you have written an add-in for Visual Studio 2008 with newly added APIs to its automation model and have configured its .AddIn file to use the Visual Studio 2008 IDE as the application host, then it’s not possible to install this add-in on machines with Visual Studio 2005 installed.
Deploying an add-in isn’t hard to do manually, but it’s been simplified by Windows Installer packages that automatically copy files on-the-fly.
In this chapter you’ll read about the following:
Steps required to deploy an add-in
Where to copy required files to
Using Windows Installer to deploy an add-in
How to use the Visual Studio Content Installer tool to simplify deployment
The Add-in Manager dialog
After reading this chapter, you’ll know everything necessary to work with the automation model and create add-ins from start to finish. In Chapter 14, you’ll learn how to localize your add-ins as well.
In previous chapters you learned about different topics connected to add-in development. You also learned important aspects... more
In previous chapters you learned about different topics connected to add-in development. You also learned important aspects of the automation model and Development Tools Extensibility (DTE). Before leaving the topic of add-ins, however, it would be useful to cover a topic that may be a concern for some developerslocalization and internationalization of add-ins.
You need to deal with this topic in the following two cases:
If you’re a developer who develops native applications for a particular culture
If you’re developing a professional multilingual add-in for several cultures
Localization of .NET applications is a broad topic involving several techniques. For add-ins, the most important concern regards text values that appear in the Visual Studio IDE for end users and that need to be localized for the specific culture.
In this chapter you’ll learn about localization of add-ins and how to target different cultures in your add-in user interface. The topics explored in this chapter include the following:
What is localization and what are its goals?
How to use embedded resources in .NET applications
How to use embedded resources to localize an add-in
As a developer, you may not be interested in localization, or think you need to know about it. Nonetheless, it’s worth taking a brief look at the topic to learn about the use of resources in add-insyou may one day find you need to use them in your projects.
You probably already know that Visual Studio has a rich IDE with many great elements. These elements of the IDE and user... more
You probably already know that Visual Studio has a rich IDE with many great elements. These elements of the IDE and user interface are common in other applications, and they can be helpful for any developer. The great features of Visual Studio toolbars, Explorer windows, or tabular structure are common in today’s user interfaces.
This part of the book describes some other options for extending Visual Studio in different ways. The first of these options is Visual Studio Shell. Visual Studio Shell (described in this chapter) enables you to bring Visual Studio IDE elements to your own applications.
There are several benefits of having such a capability:
You can begin building an IDE for your applications from a starting point. Even if your requirements are very different from what is provided by VS Shell, it’s still worthwhile because it saves you some extra work.
You can be sure of the power and correctness of what you’re using. The Visual Studio IDE has been a well-known and very popular IDE for many years; hence, you can trust it more than any other IDE.
The Visual Studio IDE has most of the common elements in today’s interfaces. For example, tabular structure among toolbars is common among user interfaces, and Visual Studio has provided these elements out of the box.
Beside these benefits for your own applications, with Visual Studio Shell you can create custom language IDEs for new development languages, or you can build your own designers. This is provided by the integrated mode of Visual Studio Shell, which is actually another name for the VSPackages described in Chapter 18.
In addition to the integrated mode, there is something new, called isolated mode, which is a part of Visual Studio Shell and is added to the Visual Studio SDK in its newest version (2008). This addition is also considered one of the main new features of Visual Studio 2008.
In this chapter you’ll learn about the following topics related to Visual Studio Shell and how to use it:
The concept of Visual Studio Shell and its applications
Integrated mode and isolated mode and their differences
How to use Visual Studio isolated mode to extend Visual Studio
How to customize an isolated IDE
How to deploy an isolated IDE
Please note that this chapter isn’t a full discussion about Visual Studio Shellin my opinion, a separate book should be written about this broad topic. Here I’ll just provide a short introduction and a quick overview outlining the basic principles of Visual Studio Shell. Unfortunately, currently there isn’t any book available about Visual Studio Shell, and online documentation isn’t rich enough to help you easily find more details about it. It is hoped that there will be more documentation from Microsoft, along with articles and tutorials from community members, in the near future. The good news is that there are some good open-source projects that are actually showcases for Visual Studio Shell, and you can take a look at their source code to learn many things.
In this chapter I’ll use the Visual C++ language for developing my Visual Studio Shell isolated applications, because presently this language is the only one that has a project template for Visual Studio Shell isolated mode development. The integrated mode of Visual Studio Shell is covered in Chapter 18, so here I’ll just give an introduction to it and describe its differences from isolated mode.
The concept of domain-specific languages (DSLs) is something general in the software development world and isn’t... more
The concept of domain-specific languages (DSLs) is something general in the software development world and isn’t specifically .NET-related. In recent years, we’ve been dealing with a lot of domain-specific languages in our daily development and can cite many instances of them. For example, an instance of a domain-specific language is a class diagram designer. The first section of this chapter introduces the concept of domain-specific languages, so don’t worry if you don’t have a good understanding of them yet.
In Visual Studio we don’t need to deal with domain-specific languages directly in order to design and create them, because Microsoft has created some tools for us already. Created by members of the Visual Studio Ecosystem team, these tools, known as Domain-Specific Language Tools (or simply DSL Tools), help developers build domain-specific languages easier and faster, and are a part of the Visual Studio SDK. Therefore, you must have the Visual Studio SDK installed to enjoy the benefits of these tools and to use the sample source code of this chapter.
The team that was creating DSL tools at Microsoft was known as the DSL Tools team, but some months before the release of Visual Studio 2008 this team joined the Visual Studio Extensibility team in order to centralize their work on the Visual Studio Ecosystem Team better.
The topic of domain-specific languages, and domain-specific language tools, for that matter, is beyond the scope of a single chapter. Here, as in Chapter 15, covering Visual Studio Shell isolated mode, I’ll just give a short introduction and a quick overview of the main topics. For readers who wish to know more about DSL tools, check out the unique book Domain-Specific Development with Visual Studio DSL Tools, written by four members of the DSL Tools team at Microsoft.
In this chapter you’ll read about the following major topics:
What is a domain-specific language (DSL)?
How to create a DSL in Visual Studio
Basic concepts in DSL
What the generated solution for the DSL contains
An overview of DSL tools in Visual Studio
DSL tools, along with Visual Studio Shell, are two features of the Visual Studio 2008 SDK that offer a lot of new material to discover. Even though DSL tools were a part of the Visual Studio 2005 SDK, in Visual Studio 2008 they’re more closely integrated with Visual Studio Extensibility features than in the past.
Debugging is a main step in software development that gets a lot of time from developers during the software development... more
Debugging is a main step in software development that gets a lot of time from developers during the software development process. You should solve bugs and exceptions in your applications before shipping them to customersotherwise, obviously, these applications fail.
Debugging is a process to find and fix bugs in software or reduce the number of bugs. We expect a program to do what it was designed to do. If it doesn’t, then we know there is a problem with it. This problem may have several sources. Problems that are related to software development can be grouped as bugs and exceptions. Bugs occur frequently and are more important than exceptions, because they can stop a program from working completely, whereas exceptions just stop it in some special cases. Fixing and reducing the number of bugs is a main process in the software world. You can find numerous references about debugging in general, and about debugging for specific technologies and development tools. Also available are various debugging tools designed to make debugging easier.
In the .NET world, many debugging mechanisms are provided out of the box, and these features are part of Visual Studio. Thanks to several debugging features in Visual Studio, you can debug a .NET application in a reasonable amount of time and with good results. Some of the important debugging features in Visual Studio include the following:
Breakpoints
Attach to process
Visualizers
Watch window
Error List window
Beginning with Visual Studio 2008 and the .NET Framework 3.5, Microsoft began sharing the source code of the .NET Framework to enable developers to debug their applications more easily. Now when your application stops at some point and you need to know what’s going on behind the scenes in order to solve the problem, you can do this by looking at the source code of the .NET Framework.
Debugging consists of the following steps:
Recognizing that a bug exists
Locating the source code that causes the bug
Finding the reason for the bug
Finding a fix for the bug and applying this fix
Testing to ensure that the bug is fixed
Obviously, Visual Studio can’t help you find a reason or a fix for the bug, but its debugging features can help you in the first two steps to recognize the bug and find its source. Debugging concepts and debugging techniques, in the .NET world and Visual Studio, are considered separate topics, and a full treatment of both are beyond the scope of this book. Many excellent books address these two topics, but here I assume that you have a background in debugging and Visual Studio debugging features.
As debugging is an important aspect of Visual Studio, Microsoft has spent a great deal of time providing extensibility options for Visual Studio debugging features. This chapter discusses these extensibility options in detail and helps you extend VS debugging features for your needs.
This chapter covers the following main topics:
Different ways to extend Visual Studio debugging features
The concept of type proxies and how to write them
The concept and usage of visualizers and how to build, test, and deploy them
The chapter also includes a sample visualizer to clearly demonstrate these concepts.
Along with macros, add-ins, and visualizers, a VSPackage is a common way to extend Visual Studio.... more
Along with macros, add-ins, and visualizers, a VSPackage is a common way to extend Visual Studio. It is also the most powerful way to do it. Internal teams at Microsoft use VSPackages to create many built-in features in Visual Studio. With VSPackages, you can have complete integration between your code and Visual Studio, something that can’t be achieved with any other extensibility option.
VSPackages open doors to you with many APIs, enabling you to add custom functionality to Visual Studio, as add-ins do. However, VSPackages can give you many more capabilities to create custom packages and extend Visual Studio than are possible with add-ins. Using VSPackages, you can add your own functionality and features to Visual Studio, including your very own tool windows, designers, editors, and commands.
Note that VSPackages are the same as Visual Studio Shell integrated packages. We looked at Visual Studio Shell isolated mode in Chapter 15. Here we cover VSPackages and Visual Studio Shell integrated mode, which are the same thing. This chapter uses the term VSPackage because it’s more common and familiar for this purpose. If you read Chapter 15, then you have a good understanding of Visual Studio Shell integrated mode, and hence VSPackages.
A good example of this deep integration with the help of a VSPackage is IronPython, a language that’s integrated with Visual Studio through a VSPackage that helps Python programmers write their programs for .NET with .NET Framework classes and APIs but in Python syntax.
VSPackage is also known as the Visual Studio Integration Package (VSIP) interface, and it’s actually a COM component. You can work with VSPackages directly by writing all code from the base, but this isn’t so easy. Therefore, Microsoft has provided a rich set of ready-to-go project templates, wizards, and code samples in the Visual Studio SDK for working with VSPackages and creating them easily.
Throughout this chapter, you’ll use these tools and code templatesso installing the Visual Studio SDK is mandatory for reading this chapter. Once you install the Visual Studio SDK, it adds some sample codes and project templates for Visual Studio extensibility options. There’s also a project template for VSPackages.
Specifically, this chapter covers the following topics:
The concept of VSPackages and their application
The anatomy of a VSPackage
VSPackage Wizard in Visual Studio
Developing a VSPackage with programming codes
Testing a VSPackage
Deploying a VSPackage
Before beginning, note that the topic of VSPackages is completely correlated with COM programming and .NET interoperability with COM components. This topic is broader than one chapter can possibly cover and warrants a deeper discussion, which should be considered a part of advanced topics in Visual Studio extensibility. This chapter provides a good introduction, including some background, and avoids detailed topics.
In fact, Microsoft’s documentation and other resources for VSPackages aren’t currently very rich, and this chapter may be the only printed resource you’ll find about VSPackage development. Many developers prefer to use other extensibility options to achieve their goals because VSPackages are harder to use and develop.
As noted in the introduction of this book, one of the main goals of extending software is saving the time of users by... more
As noted in the introduction of this book, one of the main goals of extending software is saving the time of users by relieving them from some repetitive tasksin fact, this is probably the main goal.
The most repetitive task in Visual Studio is coding, isn’t it? When you think about it, coding itself consists of several repetitive tasks, such as writing casing statements, loops, properties, and fields. Therefore, automating these repetitive tasks is a common goal for developers.
Code snippets were first introduced in Visual Studio 2005 as one of its main new features. Code snippets enable you to declare a template of code and then use it as many times as you like in your applications by replacing some placeholders with appropriate names and types.
In Visual Studio 2008, code snippets are enhanced, and there are also new code snippets. These new snippets cover some new technologies, such as Windows Presentation Foundation (WPF) and Windows Workflow Foundation (WF or WWF), as in the code snippet for dependency properties.
Code snippets are related to a specific language. This means that each language has its own code snippets, and a code snippet belongs to one and only one development language (i.e., VB or C#).
Code snippets are handy tools for coders and can save you a great deal of time. The purpose of this chapter is to teach you what you need to know about code snippets, and the following topics are covered:
The concept of the code snippet and its applications
The anatomy of a code snippet
How to build a code snippet
The XML structure of a code snippet and its elements and attributes
How to manage your code snippets
One of the aspects of visual development languages (like other development languages) is the way they keep application... more
One of the aspects of visual development languages (like other development languages) is the way they keep application code in files that have templates. There are different templates for files and projects in a development language. For example, a console application has its own template while an ASP.NET web application has another template.
These templates are helpful because they save you from continually writing codes for each project or file every time you begin creating an instance of it. These project templates have been a part of Visual Studio from early versions, and new templates have been added on an ongoing basis by Microsoft, third-party vendors, and community members. Now, in Visual Studio 2008, you can use various project templates for different programming languages, technologies, and purposes.
The other benefit of these templates is that they provide consistency between all projects of the same type around the world. In addition, project development is possible for developers with different skills and knowledge.
There are several reasons why you need to be able to create custom projects and item templates and build your own templates:
You may face a new technology and want to share some project templates for it. For example, one of my friends in the Community Server community wanted to build something as a starting point for developers to create Community Server modules and tasks. He ended up with a starter kit project (a kind of project template). As another example, Microsoft itself shipped a set of plug-ins for Visual Studio 2005 with different project templates to create Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and Windows Workflow Foundation (WF or WWF) projects. These templates helped many developers begin developing applications for these technologies more quickly and easily.
Sometimes when building a specific kind of project, there’s a task that you do frequently that eats up your time. A simple solution is to create a template for this task and reuse it as needed.
Developers create specific types of files, such as different derivations of XML or specific types of a C# class. You can simplify your code by creating item templates, rather than copying and pasting a piece of code to new files every time you want to create them. For example, a friend created an item template for an XML Integrated Query that he had named Xinq (it was a simple form of XLinq technology in the .NET Framework 3.5 for the .NET Framework 2.0). His implementation made it easy to create new items to query XML data.
Now that you have an idea of how helpful a project or item template can be, here’s a list of related topics covered in this chapter:
An introduction to project templates
An introduction to item templates
Differences between project and item templates
The anatomy of project and item templates
The structure of a template manifest file
How to create a template manually
How to create a template with the Export Template Wizard
How to customize a template
How to create custom template wizards
Starter kits
After reading this chapter, you should know everything you need to begin creating project and item templates.
Visual Studio templates can be grouped into two categories: project templates and item templates. This chapter covers both types, including their similarities and differences.
Like debugging, build and compilation is another main stage in the software development process. You learned all about... more
Like debugging, build and compilation is another main stage in the software development process. You learned all about extending the debugger in Visual Studio in Chapter 17; now it’s time to look at the build and compilation process, and all the extensibility points that are provided by Visual Studio for this stage.
I don’t need to describe the concept of build and compilation of software here, but how is this stage implemented in .NET? Some readers may have a background in this, but others may not. Microsoft has tried to provide an automatic way to simplify the process of building, compilation, deployment, and logging. Yes, deployment! You may say that deployment is another stage in software development and you’re 100 percent right, but Microsoft has provided some means to tie these two stages and automate them.
In the first sections of this chapter you’ll learn more about MSBuild and its applications, but first I’ll provide a short introduction to this important topic, as MSBuild is a platform that enables you to write automated builds, thereby simplifying this stage of your projects.
In this chapter you’ll learn about the following topics:
The concept of MSBuild and its applications
The anatomy of MSBuild files
The structure of MSBuild files and common elements of MSBuild
How to write MSBuild files
How to write a custom MSBuild task
How to use MSBuild files
As with Chapters 19 and 20, this chapter relies heavily on XML and related concepts because MSBuild files are XML documents. Unlike Chapters 19 and 20, which described all possible elements and attributes for an XML schema, I won’t go into detail here about some uncommon elements and attributes; the vast number of these elements and attributes is beyond the scope of a chapter. However, you can get more information by reading online documentation and articles (such as MSDN documents).
This chapter is independent from .NET development languages to some extent, and you’ll see a few sample projects showing how to build and deploy with MSBuild.
In Chapter 3, “Quick Tour,” you had a short introduction to macros, including a very simple example to get... more
In Chapter 3, “Quick Tour,” you had a short introduction to macros, including a very simple example to get an initial feel for them. As you learned there, macros can be written only with Visual Basic; and as this book focuses on C# as the primary development language, I moved the content for macros to this part of the book. Macros remain a major aspect of Visual Studio extensibility and therefore must be discussed.
As you learned earlier, a macro is the answer to the need for a time-saving solution for repetitive tasks in daily work with computer software. Many Microsoft products support macros, especially those products built based on an IDE with an editor. For example, products such as Office Word, Office Excel, and Visual Studio have excellent built-in support for macros.
The purpose of this chapter is to show you everything you need to know in order to use macros and write your own macros for Microsoft Visual Studio. The chapter covers the following topics:
An introduction to macros
Anatomy of macros
Macros IDE
Macro Explorer
Different ways to build a macro
How to record a macro
How to write a macro
How to debug a macro
How to deploy a macro
Simplifying the process of running a macro
After covering these topics, you will have a basic understanding of macros and how to work with Visual Studio macros. This chapter teaches by way of examplewalking through the source code of the examples will clearly demonstrate the details of macro development. A good background in Visual Basic syntax is required for understanding this chapter.
Here is a list of third-party add-ins and extensions written by companies, open-source projects, and community members.... more
Here is a list of third-party add-ins and extensions written by companies, open-source projects, and community members. Some of these add-ins and extensions are completely free, some of them have a free and a commercial version, and others are completely commercial. Note that many more third-party add-ins and extensions could be listed here, but I chose some of the more well-known and helpful ones, to let you discover some real-world examples of what you saw in theory in this book.
Appendix B contains a list of useful resources for further reading, including communities, blogs,... more
Appendix B contains a list of useful resources for further reading, including communities, blogs, and other books.
Purchase Before purchasing this product, please be sure you have met all software and system requirements, and that you understand any limits placed upon its use.
Return Policy Wrox Chapters on Demand are non-returnable and non-refundable.
Reader Software Wrox Chapters on Demand are offered as PDFs, and they must be viewed using the Adobe Reader. If you do not have the Reader installed, it can be downloaded for free at Adobe.com.
Test Download As Wrox Chapters on Demand purchases are non-returnable, it is advisable that you test your system and software configurations with a free sample download before you place an order.
Usage Rights for a Wrox Chapter on Demand File Any Wrox Chapter on Demand product you purchase from this site will come with certain restrictions that allow Wiley to protect the copyrights of its products. After you purchase and download this title, you:
If you have any questions about these restrictions, you may contact Customer Care at (877) 762-2974 (8 a.m. - 5 p.m. EST, Monday - Friday). If you have any issues related to Technical Support, please contact us at 800-762-2974 (United States only) or 317-572-3994 (International) 8 a.m. - 8 p.m. EST, Monday - Friday).
Related Books
.NET Resources