Microsoft Visual Studio Tools for Applications 2012 (VSTA) gives you a way to enable end users to customize your existing applications using Visual Basic and Visual C#. You can incorporate the use of the Visual Studio integrated development environment (IDE) into your application to enable end user customization. End-user developers can use the IDE to customize the application by creating add-ins that extend the functionality of the application to meet their needs.
Visual Studio Tools for Applications 2012 provides two primary modes of operation: with Visual Studio 2012 Professional, Premium or Ultimate installed and standalone. In standalone mode, VSTA provides your application with the means to load, compile, and run end user customizations. With Visual Studio 2012 Professional, Premium or Ultimate installed, VSTA extends that functionality with the means to edit and debug those customizations.
Visual Studio Tools for Applications 2012 presents a new and simplified API for integrating design-time experiences into your application. Host application integrations can be implemented by using either managed (Visual C# or Visual Basic .NET) or unmanaged (Visual C++) code. The VSTA hosting API enables you to integrate your application because the API simplifies tasks such as finding the installation of Visual Studio, launching the external process, and synchronizing save state.
Visual Studio Tools for Applications 2012 provides the ability to upgrade projects from Visual Studio 2005 Tools for Applications and Visual Studio 2008 Tools for Applications, compile, and run them.
Visual Studio Tools for Applications 2012 does not require a runtime library for end user customizations. This gives the integrator the flexibility to choose the method of running user code best tailored to the host application. The Microsoft .NET Framework includes the Managed Add-in Framework, which can be used to run add-ins built on Visual Studio 2008 Tools for Applications.
Minimum system requirements:
· Windows 7
· .NET Framework 4.5
· 2 GB of RAM
· 4 MB of hard disk space
Runtime requirement:
· Visual C++ Redistributable for Visual Studio 2012 Update 1
To enable editing and debugging:
· Microsoft Visual Studio 2012 Professional, Premium or Ultimate
To integrate an application with Visual Studio Tools for Applications 2012, you must understand a few simple concepts.
Definitions
Host Application: An application that is capable of being extended through end user code. A host application “hosts” the end user code by giving it the facilities to be compiled and run, facilitated by the technologies in VSTA.
Integrated Development Environment (IDE): An application (in this case, Visual Studio 2012) that allows a user to compile, edit, and debug code. Visual Studio 2012
Project Template: A collection of source files and XML that are used at runtime for the creation of projects that can be customized by end user code.
Session: An instance of a collection of projects that can be associated with one IDE. This encapsulates all of the services that can be done between zero or more projects and a single running IDE instance.
VSTAX: An Open Packaging Container (OPC) file that contains one or more project templates. A VSTAX file is typically created by the host application vendor, shipped with the application, and used at runtime to create a project for an end user to customize.
VSTA includes versions of the hosting API for both managed and unmanaged integration. This document will demonstrate use of the API in Visual C#, but all scenarios can be accomplished using Visual C++ and Visual Basic .NET as well.
Before you can install and run this version of VSTA, the Microsoft .NET Framework 4.5 must also be installed.
Microsoft ships a software development kit (SDK) for VSTA apart from the VSTA download. After the VSTA SDK is installed, its components are placed into the Program Files (x86)\Microsoft SDKs\VSTA\11.0 folder.
To build an application, you need only the .NET Framework SDK (available as a free download from Microsoft), but examples in this document will be shown using Visual Studio 2012.
After the VSTA SDK is installed, you can launch Visual Studio from your application by using Visual C# if you add a reference to one assembly and then write three lines of code.
To enable an application to launch the IDE:
using VSTA = Microsoft.VisualStudio.Tools.Applications;
private VSTA.Session _session;
private void button1_Click(object sender, EventArgs e)
{
if (_session == null)
var sessionMgr = VSTA.SessionManager.Create("MyHostApp");
_session = sessionMgr.CreateSession();
}
_session.Ide.Show();
This code does the following:
1. Creates a session if one hasn’t already been created. This starts up the base-level scaffolding required to communicate with an IDE and manage projects.
2. On the session’s Ide instance, shows the IDE. This will implicitly launch the IDE process, open a communication channel to the IDE, and tell the IDE to show the main window.
NOTES:
· A session’s name must be unique in the context of the running Host Application instance. In other words, the “if(_session == null)” condition prevents another session from being created with the same name each time a user chooses the button. This situation can lead to a deadlock condition when the Ide object is accessed.
· Session and SessionManager objects are, in fact, IDisposable. If you use these objects, you must use proper implementation of IDisposable for classes that hold onto instances of these objects. If you failing to hold onto instances of these objects, the .NET garbage collector can dispose of them, which leads to exceptions.
To creating a project in VSTA, you must choose a project template. This template provides the basic framework of project source files needed to enable end users to add their code to the solution.
In VSTA, project templates are packaged in VSTAX files. These files contain one or more templates that can be redistributed with your host application. These project templates work differently from project templates that are deployed with Visual Studio 2012, in that VSTA templates do not need to be installed with Visual Studio. This allows the host application complete control of template deployment.
VSTA templates provide built-in facilities for replacement tokens (for example, “$projectname$”), guid generation (for example, “$guid2$”), and SNK file generation during project creation.
You can create templates for VSTA projects by using TemplateGenerator.exe, a command-line tool included in the VSTA SDK in the folder %ProgramFiles(x86)%\Microsoft SDKs\VSTA\11.0\Tools. You can use this tool to create a VSTAX file, which VSTA can then consume to create projects.
To create a template:
janpanewka