| Author: |
Carlos J. Quintero (Microsoft MVP) |
Applies to: |
Microsoft Visual Studio 2005 |
| Date: |
August 2011 |
|
Microsoft Visual Studio 2008 |
| Updated: |
October 2012 |
|
Microsoft Visual Studio 2010 |
| |
|
|
Microsoft Visual Studio 2012 |
Introduction
This article explains how to create an add-in that targets Visual Studio 2005 or
higher using the same source code and the same output binary DLL.
More Information
To create an add-in that can target Visual Studio 2005, 2008, 2010
and 2012 using the
same source code and the same output binary Dll (no conditional compilation)
follow these considerations:
- Use .NET Framework 2.0. Do not use .NET Framework 3.0, 3.5, 4
or 4.5.
A .NET Framework is composed of a Common Language Runtime (CLR) and some
libraries:
- .NET Framework 2.0, .NET Framework 4 and .NET Framework 4.5 provide its own CLR.
- .NET Framework 3.0 and .NET Framework 3.5 only provide new libraries without
introducing their own CLR, using the CLR 2.0 of the .NET Framework
2.0 instead.
Regarding Visual Studio versions:
- Visual Studio 2005 "out of the box" uses only .NET
Framework 2.0. To use .NET Framework 3.0, some extensions are required to be
installed.
- Visual Studio 2008 can use .NET Framework 2.0, 3.0 or 3.5 (all of them use CLR
2.0).
- Visual Studio 2010 can use .NET Framework 2.0, 3.0 or 3.5 (all of them use CLR
2.0), although they need to be installed separately, or .NET Framework 4 (uses CLR 4.0).
- Visual Studio 2012 can use .NET Framework 2.0, 3.0, 3.5 (all of them use CLR
2.0), although they need to be installed separately, or .NET Framework 4 (uses CLR 4.5)
or .NET Framework 4.5 (uses CLR 4.5).
Therefore:
- Visual Studio 2005 and 2008 can use only CLR 2.0, so that discards .NET
Framework 4 and 4.5.
- Visual Studio 2005 is installed by default with only .NET Framework 2.0, so
that discards .NET Framework 3.0 and 3.5 (they would not be installed on a
target machine with only Visual Studio 2005 without Visual Studio 2008).
- Although a machine with only Visual Studio 2010 or 2012 would not have .NET Framework
2.0 installed, assemblies compiled against .NET Framework 2.0 can run on .NET
Framework 4.0 or 4.5.
- Create a single project using either Visual Studio 2005, 2008, 2010 or 2012. That is,
despite using .NET Framework 2.0 you are not required to use Visual Studio 2005
(or 2008 or 2010), you can use Visual Studio 2012.
- Use the following references (see the article INFO: Assemblies used in Visual Studio Extensibility):
- EnvDTE
- EnvDTE80
- Extensibility
- Microsoft.VisualStudio.CommandBars
- VSLangProj
- VSLangProj2
- VSLangProj80
- VsWebSite.Interop
- Do not use the following references (which are not installed by Visual Studio
2005):
- EnvDTE90
- EnvDTE90a
- EnvDTE100
- VSLangProj90
- VSLangProj100
- VSLangProj110
- VsWebSite.Interop90
- VsWebSite.Interop100
- The add-in can know the version of Visual Studio where it is loaded using the
DTE.Version property, which returns:
- 8.0 for Visual Studio 2005
- 9.0 for Visual Studio 2008
- 10.0 for Visual Studio 2010
- 11.0 for Visual Studio 2012
- To register the add-in for Visual Studio using XML registration (.AddIn file) (see the article
INFO: Default .AddIn file locations for Visual Studio add-ins) you can:
- Use a single .AddIn file in a common folder for all Visual Studio versions
(such as "%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\AddIns" to
register the add-in for all users, or "%APPDATA%\Microsoft\MSEnvShared\AddIns"
to register the add-in for the current user). The .AddIn file must
specify all host Visual Studio versions that it targets:
<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility"> <HostApplication> <Name>Microsoft Visual Studio</Name> <Version>11.0</Version> </HostApplication> <HostApplication> <Name>Microsoft Visual Studio</Name> <Version>10.0</Version> </HostApplication> <HostApplication> <Name>Microsoft Visual Studio</Name> <Version>9.0</Version> </HostApplication> <HostApplication> <Name>Microsoft Visual Studio</Name> <Version>8.0</Version> </HostApplication> <Addin> ... </Addin> </Extensibility>
- Use a different .AddIn file in a folder specific for each Visual Studio version
(such as "%VSCOMMONAPPDATA%\AddIns" to register the add-in for all users or
"%VSAPPDATA%\AddIns" or "%VSMYDOCUMENTS%\AddIns" to register the add-in for the
current user).
- The add-in can know the registry key of the Visual Studio where it is
loaded using the DTE.RegistryRoot property, which returns:
- "Software\Microsoft\VisualStudio\8.0" for Visual Studio 2005
- "Software\Microsoft\VisualStudio\9.0" for Visual Studio 2008
- "Software\Microsoft\VisualStudio\10.0" for Visual Studio 2010
- "Software\Microsoft\VisualStudio\11.0" for Visual Studio 2012
- The add-in can store settings common to all Visual Studio versions in a
registry key such as HKEY_CURRENT_USER\Software\<add-in>, or settings specific
to a Visual Studio version in registry keys such as
HKEY_CURRENT_USER\Software\<add-in>\VS2005,
HKEY_CURRENT_USER\Software\<add-in>\VS2008, etc.
- Since the add-in targets several Visual Studio versions with the same binary
dll, the setup of the add-in does not require to detect which versions of Visual
Studio are installed. The add-in can be registered even for Visual Studio
versions that are not installed (specially when using a single .AddIn XML
registration file, as explained above).
Related articles
Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this
|